AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [Snippet] [TF2]adding damage fall off on weapons using linear regression (https://forums.alliedmods.net/showthread.php?t=227519)

nergal 10-02-2013 18:53

[Snippet] [TF2]adding damage fall off on weapons using linear regression
 
This code snippet is useless for me at the moment, but might prove useful in the future for future projects.

PHP Code:

                Max 1024 //the maximum units that the player and target is at (assuming you've already gotten the vectors) 
                
base damage//base becomes the initial damage 
                
multiplier = (MinFallOffDist Max); //divides the minimal distance with the maximum you've set
                
falloff = (multiplier base);  //this is to get how much the damage will be at maximum distance
                
Sinusoidal = ((falloff-base) / (Max-MinFallOffDist));  //does slope formula to get a sinusoidal fall off
                
intercept = (base - (Sinusoidal*MinFallOffDist));  //this calculation gets the 'y-intercept' to determine damage ramp up
                
damage = ((Sinusoidal*dist)+intercept); //gets final damage by taking the slope formula, multiplying it by your vectors, and adds the damage ramp up Y intercept. 

example in psuedocode

your grenade launcher does 100 damage, you want it to go half lower from distance and half higher when closer
max distance = 1024
minimum = 512
multiplier = 0.5
falloff = (100 * 0.5) = 50
sinusoidal (50-100)/(1024-512) = -50/512
y intercept becomes 100 - (-50/512(512)
-50/512 * 512 = -50
base - -50 = 150 or 1.5x as your damage ramp up
finally your damage will be -50/512 * distance vectors + 150 y intercept

let's say you shot the grenade from 786 units
-50/512(786) = -75
-75 + 150 = 75; 75 damage from 786 units!

512 units, aka minimum damage fall off distance = -50/512(512) + 150 = 100

now the farthest distance in tf2, 1024 = -50/512(1024) + 150 = 50

thus it's correct!


All times are GMT -4. The time now is 18:33.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.