- Home /
Get the direction of an AI Character
How can I get the direction of a moving GO? If I use the Input, I will get values between -1 and 1 for Side and Forward. But how can I get those values of an AI? If I use the last position and current position and divide it by Time.deltatime, I get awful values... for example if my AI goes constantly right, I get a list of values like this: 0.13514, 0.41245, 0.63456, -0.14833 and so on... All I want is to get values between -1 and 1 and to be constant, not like those above.
Wouldn't just calling transform.forward on your moving GO give you the vector it is facing?
Answer by malkere · Aug 27, 2018 at 11:53 AM
gameObject.transform.forward will return the Vector3 normalized direction. If you're only rotating around the y axis, then only the x and z values will be populated, which you can use sin and cosine to calculate an angle if you like.
you don't need to call gameObject.transform :) transform is accessible directly
Your answer
Follow this Question
Related Questions
How to get object to face direction it's flying rather than looking at the target 2 Answers
Modify rotation based on passing rigidbody's velocity and direction? 1 Answer
how to find rotation from direction of velocity 1 Answer
Vector2.MoveTowards and Rigidbody2D Velocity 3 Answers
Velocity direction help 1 Answer