- Home /
Get angle relative to GameObject
I have two GameObject's that are rotated at a arbitrary angle and in a script attached to one of the GameObject's I would like to know the angle to the other GameObject relative to its own rotation. In the following illustration I have the script attached to the lower object and I want to know the "red" angle. In this illustration they are both pointing up, but that will not always be the case as they both rotate at will. I have tried many things now but it just does not work for me, but I am sure it is easy? Any ideas on how to do this?
Answer by neigaard · Jun 26, 2014 at 08:45 AM
That was actually easy... I simply did this (transform.up is my forward):
Vector2 toVector = target.transform.position - transform.position;
float angleToTarget = Vector2.Angle(transform.up, toVector);
Your answer
Follow this Question
Related Questions
How do I find slope on a spherical terrain 2 Answers
Find Vector3 from a starting Vector3, angle, and distance. 1 Answer
Angle between two lines in 2D 3 Answers
Vector3.Angle returning wrong values for vectors with small components 2 Answers
How can I calculate the Vector3 b using Vector 3 a pos with an angle? 1 Answer