- Home /
How to get the direction of the velocity of an object (c#)
I'm new to unity. But I have created a small game (for learning purposes) where you control a ball as it rolls around the ground. The camera follows the ball, but if you move the ball backwards the ball will be rolling toward the camera. I am trying to change this.
Because the ball is constantly rolling, its "forward" is rarely the direction in which it is traveling in. In order to always keep the camera "behind" the ball (on the side that it is moving away from) I need to constantly be rotating the camera as the direction of the velocity of the ball changes.
I am looking for a method, something like "ball.transform.getVelocityAngle()" to get me the direction or angle of the velocity.
EDIT: Also, if anyone knows a method that tells you if an object is resting on something (i.e is the ball touching the ground, yes or no?) that would be great.
DOUBLE EDIT: I need to get my username changed. Pronto. Didn't realize they were asking for a screen name......
Answer by hoy_smallfry · Mar 20, 2013 at 05:33 PM
rigidbody.velocity is what you are looking for, and possibly Vector3.Normalize()
Your answer
Follow this Question
Related Questions
Velocity bug with hinge joints forces in C# 0 Answers
How to calculate direction between 2 objects 2 Answers
Adding force to an object based on its current angle. (2D) 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers