Sign in to follow this  
OneEyed

Vehicle Spring Damping Velocity

Recommended Posts

I've created a Spring for my vehicle to stay above ground with this formula. vFinal = ((-springStiff * vDistance) + (-springDamp * vPointVelocity)) * m_flFrametime; The problem I'm having is with vPointVelocity. This is getting the velocity at the tire origin. What I need is to extract the downward velocity from vPointVelocity, so my Spring only works along the gravity vector. The gravity vector can rotate, so I can't just grab the Z value of vPointVelocity. I know DotProduct is the answer to my problem in some form, I just can't think up a way to properly extract only the velocity heading in the direction of my gravity vector. Any help would be appreciated!

Share this post


Link to post
Share on other sites
You'll need to project the velocity vector onto the gravity vector then. Assuming the gravity vector is a unit vector (lenght of 1), you can use the following:

vSpringVelocity = dot(vPointVelocity, vGravity) * vGravity;

vSpringVelocity will then be the "portion" of vPointVelocity along vGravity. If vGravity is not a unit vector, you can use

vSpringVelocity = dot(vPointVelocity, vGravity) * vGravity / length2(vGravity);

where length2(v) computes the square of the length of the vector v (ie |v|^2).

edit: here's a good post describing it in a bit more detail:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this