Vehicle Spring Damping Velocity

Started by
1 comment, last by JoeOfTexas 15 years, 9 months ago
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!
Advertisement
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:
Yes that gives me what I needed, thanks!

This topic is closed to new replies.

Advertisement