- Home /
Question by
Vectorizing · Dec 06, 2013 at 05:14 AM ·
physicsgravity
How can I find the angle of the direction the velocity is pointing?
Hello,
I have a rigidbody that I can move by adding a force. My question is how can i dtermine the angle at which the object is moving?
Here is a picture I have made to demonstrate this:
unity angle image.jpg
(19.3 kB)
Comment
I believe that Vector2.Angle() is signed, so it should do the job. As an alternate that uses Vector2.right as the reference:
var angle = $$anonymous$$athf.Atan2(fromVector.y, fromVector.x) * $$anonymous$$athf.Rad2Deg;
Answer by Moor · Dec 06, 2013 at 05:29 AM
Use `Vector3.Angle(fromVector3, ToVector3)` for 3d
use `Vector2.Angle(fromVector2, ToVector2)` for 2d
It's 2d, so I would use this:
Vector2.Angle(gameobject.transform.position, rigidbody.velocity);
Im not sure if this is correct..
Thanks for your help so far!
ya try, need to update gameobject.transform.position
value before getting angle because ur object is moving..