Answers for "Vector3.Angle returning wrong values for vectors with small components"
http://answers.unity.com/questions/160514/vector3angle-returning-wrong-values-for-vectors-wi.html
The latest answers for the question "Vector3.Angle returning wrong values for vectors with small components"Answer by elliselkins
http://answers.unity.com/answers/1174912/view.html
I ran into this problem as well, so I wrote my own angle functions.
//This returns the angle in radians
public static float AngleInRad(Vector3 vec1, Vector3 vec2)
{
return Mathf.Atan2(vec2.y - vec1.y, vec2.x - vec1.x);
}
//This returns the angle in degress
public static float AngleInDeg(Vector3 vec1, Vector3 vec2)
{
return AngleInRad(vec1, vec2) * 180 / Mathf.PI;
}
See [Atan2][1] for more details.
[1]: http://docs.unity3d.com/ScriptReference/Mathf.Atan2.htmlThu, 21 Apr 2016 20:23:50 GMTelliselkinsAnswer by Adrian
http://answers.unity.com/answers/160517/view.html
Normalizing probably is the issue here. The documentation on [Vector3.Normalize][1] states:
> If the vector is too small to be normalized a zero vector will be returned.
`Vector3.Angle` probably normalizes the input vectors, calculating the angle between `(1, 0, 0)` and `(0, 0, 0)`. `Vector3.Angle` also seems to return `90` when either of its input vectors has zero length.
[1]: http://unity3d.com/support/documentation/ScriptReference/Vector3.Normalize.htmlFri, 26 Aug 2011 11:24:58 GMTAdrian