Hello, what i want to achieve is some method or a formula i can use to calculate the damage based on distance(ramp up and fall off). Where if my gun’s origin position - the hitpart’s position magnitude is less than lets say 20 studs, it will incrementally do more damage until it reaches a maximum damage ramp up multiplier, and vice versa for falloff, where the maximum rampup multiplier is 1.5x more damage dealt and max damage falloff is 0.3x of your damage dealt.
I have looked all over the forums and even on youtube but i couldn’t find an exact way to calculate it. Any help is appreciated.
Found it, to tailor fit it better, you can use create the line from two points.
The trick is figuring out which variables represent and translating it to english.
local function linearDropOff(distance, distanceWhereDamageStartsDropping, distanceWhereDamageStaysMinimum, maxDamage, minDamage)
local slope = (minDamage-maxDamage)/(distanceWhereDamageStaysMinimum-distanceWhereDamageStartsDropping)
local solvedEq = slope*(distance-distanceWhereDamageStartsDropping)+maxDamage
return math.clamp(solvedEq,minDamage,maxDamage)
end
here is the Desmos graph, try playing around with it.
local Distance = whatever --Total distance away from target
local Range = whatever --range of gun or whatever
local BaseDamage = whatever
local NewDamage = nil
local Multiplier = nil
local Falloff = nil
if Distance =< 20 then -- 20 or closer
Multiplier = (1.5/Distance)
NewDamage = BaseDamage + (BaseDamage*Multiplier)
else--further then 20 studs
local TempSum = Range/Distance
Falloff = (.33/TempSum) -- subtract this from the base damage
NewDamage = BaseDamage - Falloff*100
end
print("Damage was"..BaseDamage..". Now its "..NewDamage)
Here’s a better explaination of what variables im using in my system to use for damage rampup and falloff.
I’m using a multiplier to scale damage based on distance, where the base damage(a constant) is multiplied by that calculated multiplier to get the actual damage.
multiplier for max ramp up is 1.5x and multiplier for max falloff is 0.3x
The max ramp up im using here is 5 studs away from target so if your closer than 5 studs it will still return your damage x 1.5 and max falloff is 70 studs so vice versa goes for falloff.
The base damage distance however is 20 so any distance less than 20 counts as rampup and any distance over 20 counts as falloff.
Hope this provides more background for my question
So is it the same dropoff system as my graph is mentioning? Maybe a more visual method helps that’s what graphs are for.
As for the explanation
distanceWhereDamageStaysMinimum is equal to variable b in the desmos graph. Any distance more than this variable will stay the minimum multiplier of 0.3x
and distanceWhereDamageStartsDropping is equal to a in the desmos graph. Any distance more than this variable starts dropping the multiplier from 1.5x to 0.3x.