I want to have damage reduction in my FPS game where up to 20 studs the damage is the max damage(34) and past 90 studs the minimum damage(22). But In between I want the damage to reduce in between the two points evenly.
The problem is I don’t know where to start. I’ve looked on the internet and back at school and a linear growth equation would probably get the job done.
Sorry I can’t provide more information but I don’t know where to start and I haven’t used math much in Roblox.
Subtract the magnitude of the players position and the targets position to get the distance of the target. After you have the distance you can check if the distance meets the requirements and put your desired damage input.
local MAX_DISTANCE = 90
local MIN_DISTANCE = 20
local MAX_DAMAGE = 34
local MIN_DAMAGE = 22
local function getDamage(distance)
local calulcatedDamge = MAX_DAMAGE - (MAX_DAMAGE-MIN_DAMAGE)*(distance-MIN_DISTANCE)/(MAX_DISTANCE-MIN_DISTANCE)
return math.clamp(calulcatedDamge, MIN_DAMAGE, MAX_DAMAGE)
end
This would have the damage calculated depending on the distance if it’s between the minimum and maximum distance values. If the player is really close it will return maximum damage and vice verse for far players.