Raised This Month: $ Target: $400
 0% 

[Snippet] [TF2]adding damage fall off on weapons using linear regression


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
nergal
Veteran Member
Join Date: Apr 2012
Old 10-02-2013 , 18:53   [Snippet] [TF2]adding damage fall off on weapons using linear regression
Reply With Quote #1

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!
__________________

Last edited by nergal; 10-02-2013 at 19:10.
nergal is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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