- Home /
Question by
zero3growlithe · Nov 21, 2011 at 03:09 PM ·
raycastdistance
Raycast: The closer the object is, the bigger is force.
How do i make my script make one value inversly proportional to the other value?
example:
X gets smaller so Y gets bigger.
Comment
Best Answer
Answer by DoktorAce · Nov 21, 2011 at 03:33 PM
I'm not quite sure what you're after, but it sounds like this (In C#)
float actualDistance = 5.0F //Replace this with the distance you got from the ray cast
float minForceDistance = 100.0F //This would be the distance where the force would be zero
float maxForce = 10.0F //This is the force that will be applied when the object is very close to the ray cast origin
float force = ( 1 - Mathf.Clamp01( actualDistance / minForceDistance ) ) * maxForce;
Hope it helps!