I have my own 2d game and I am attempting to calculate the angle between 2 GameObjects.
My Problem: My function that is meant to calculate the angle(direction) between 2 Vector3's doesn't appear to be correctly calculating the angle. It always returns a value thats between 89.1 and 89.9, its never any other value.
What am I doing wrong? Can you help me to get my function to correctly calculate the angle between 2 Vector3's?
Do you know that Unity already provide such methods? Vector3.Angle
Anyway there is something wrong in your formula because you use squared magnitude instead of magnitude. The angle between two vectors is:
where . is the dot product and ||v|| is the magnitude of the vector v.
But like I said, all methods are already provided by Unity. See the reference for Vector3.