# Vehicle Spring Damping Velocity

This topic is 3816 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 on other sites
Yes that gives me what I needed, thanks!

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633734
• Total Posts
3013591
×