- Home /
Question by
NinjaSquirrel · Oct 15, 2011 at 10:32 PM ·
rigidbodyvelocityspeed
Linear Velocity
Hi, I want to know how I could find the linear velocity of an object? i.e. how fast it's going in a certain direction (transform.forward).
Comment
Answer by Mike McFarland · Oct 16, 2011 at 03:37 AM
The rigidbody has the velocity of a given game object. If you want the projection of one vector onto another then what you are looking for is the dot product
so for c#)...
float speedForward = Vector3.Dot(rigidbody.velocity,transform.forward);
which assumes this is a behaviour on a gameobject with a rigidbody...
these pages may be helpful:
http://www.mvps.org/directx/articles/math/dot/index.htm http://unity3d.com/support/documentation/ScriptReference/Rigidbody-velocity.html