I’m currently working on a FPS game, and during the coding process I have realized a major thing that a majority of first person shooters have: damage drop-off based on range. Damage dealt by a bullet would decrease the further it would travel. This is a pretty important thing for balancing purposes, so I’ve been thinking on how I would do it.
After experimenting, I’ve come up with a formula/equation for that, and I decided to share it because I haven’t seen any posts about it so far.
Here is the full formula, including annotations and variables:
--set up some variables related to the damage local baseDmg = 30 local minDmg = 18 local maxDmgRange = 40 --this number indicates the maximum range within the base damage shouldn't change local damage local distance local multiplier = 1 --you can also add multipliers based on the hit bodypart if you want --shootevent would go here distance = 50 --there are various ways on getting the distance, based on the way you handle projectiles damage = math.clamp((baseDmg/(math.clamp(distance/maxDmgRange,1,2)))*multiplier,minDmg,baseDmg*multiplier)
The last line may seem very confusing on first sight, so let’s take a closer look!
Here, we use math.clamp to return a number between two other given numbers. The base damage gets divided by the distance divided by the max damage range. If the distance is below the max damage range, the base damage gets divided by one so it stays the same.
(The second math.clamp parameter should always be set to one, otherwise if the distance is lower than the maxdmgrange, it would divide the base damage by a decimal below 1 which would lower the base damage.)
Then for the third parameter, that defines the maximum distance division, which means in this case, the lowest possible damage is 15, but we have hard setted it to 18 in the min damage variable.
Afterwards, we multiply the given damage with a multiplier (optional, based on hit body part, set to 1 if you have not implemented that), then the damage gets clamped between the minimum damage and base damage, also multiplied by the same multiplier (important if your gun should one shot head for example, you would have to bypass the base damage)
That’s pretty much it, feel free to let me know your thoughts about it.
Thanks for reading