Tf2 style damage ramp up and fall off (Text math formula included for any sort of regular code)

This guide will teach you how to calculate a hitscan weapon's Damage ramp up and fall off, as well as deciding when the bullet damage starts ramps or fall or just use the base damage

Updated almost 3 years ago Edit Page Revisions

Hello, i'm a novice proggramer, so you might find some mistakes or lack of optimization in my code, so feel free to correct me on anything or you wanna add something :)

email:- samoaprem60@gmail.com

this is for HitScan weapons, but the same concept can be used.

Variables you need:

  • Out Hit Distance (from a linecast, Hit Result Value).
  • Base damage of the weapon (Example for guide: 12.0).
  • Max range of weapon (Example: 5000.0).
  • Three FloatRange type variables: RampUpRange(0 - 900), BaseDamageRange (900 - 1200), FallOffRange(1200 - MaxRange).

First, we check if the OutHitDistance is in the base damage ranges, ramp up ranges, or in fall off ranges.

If the Out Hit Distance is in base damage ranges (900 - 1200), we simply just return the base damage.

However, if the Out Hit Distance is in the Ramp Up Range (900 - 0), we do the following Calculation:

NOTE:- you cant just copy paste this to c++ code, its not accurate to actual c++, this is basically how the formula might look like in in regular code.

WeaponDamage + (NormalizeToRange(MakeNegative(OutHitDistance), MakeNegative(RampUpRangeLowerBoundValue), RampUpRangeLowerBoundValue) * WeaponDamage).

The lower bound becomes max range of the normalize, and the Upper bound becomes minimum range (-900, 0).

For example, if the distance is 600, we make it -600, and compare it's distance between (-900, 0) so if we are much closer 0 (Closer to target), we get more ramp up, but if we are closer to -900 (Further from target) we get less ramp up.

Please do not ask me how this works, i already used to much of my braincells trying to write this guide today.

dont worry about the fall off, its much easier :)

For Fall off the calculation is much simpler:

  • WeaponDamage - (NormalizeToRange(OutHitDistance, FallOffLowerBoundValue, FallOffUpperBoundValue) * WeaponDamage)

for the (NormalizedToRange * WeaponDamage) part, i used this simple formula i learned in algebra class to find percantages:

  • What(x) is (=) 50% (0.5) Of (*) 10, or X = 0.5 * 10

the result of the example given here is 5 because 50 % of 10 is 5.

Thanks for reading my guide, and please, if you want to add something doing or if you found any mistakes, correct me.

email:- samoaprem60@gmail.com

Bye!