Need a little math help...

Blitz3D Forums/Blitz3D Programming/Need a little math help...

OrcSlayer(Posted 2004) [#1]
I'm currently creating a game engine which is now almost finished (finally). I have had very few problems and things are progressing nicely, but I need someone to help me out with a little math problem. I used to be able to do stuff like this, but my memory of such things is not so good it seems...

Anyway, it's for projectiles that have a damage radius, the code needs to make it do 100% at 0 distance and 0% at the max distance. The values that I have to work with are the Radius of the projectile, Distance of the projectile from the entity taking damage, and maximum Amount of damage, which as I said should be 100% at 0 distance and 0% at maximum distance. Currently my code does full damage all the way out to the value of Radius, I just need to have a math function that can take Radius, Distance, and Amount and return an amount that is relative to distance as I described. Thanks to whoever can help me out!


Michael Reitzenstein(Posted 2004) [#2]
Where MaxDamage is the damage inflicted by the projectile at distance equals zero, MaxDamageDistance is the radius around the projectile that is effected by the damage, and ToBeDamagedDistance is the distance from the projectile to the entity in question;

Global MaxDamage#, MaxDamageDistance#, ToBeDamagedDistance#

Damage# = InterpolateLock( MaxDamage#, 0.0, ( ToBeDamagedDistance / MaxDamageDistance ) )

Function InterpolateLock#( Start#, Finish#, Progress# )
	
	If ( Progress < 0 )
		
		Progress = 0
		
	EndIf
	
	If ( Progress > 1 )
		
		Progress = 1
		
	EndIf
	
	Return ( Start + ( Finish - Start ) * Progress )

End Function



Curtastic(Posted 2004) [#3]
I think it would be:
percent=float(maxdistance-distance)/radius*100


OrcSlayer(Posted 2004) [#4]
Works like a dream. Thanks a lot!


aab(Posted 2004) [#5]
Thats what i always do for things like distant objects fading out. for some reason ive never used fade entity...