Comments and 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 comments and answers for the question "Vector3.Angle returning wrong values for vectors with small components"Comment by VirtualSUN on VirtualSUN's answer
http://answers.unity.com/comments/1573669/view.html
Ok, but something going wrong:
A & B is a Vector2.
if we do this
Mathf.Atan2(B.y - A.y, B.x - A.x) * 180 / Mathf.PI
then we got that
A (1.0, -1.0) B (-1.0, 1.0) = 135
???Wed, 21 Nov 2018 08:23:55 GMTVirtualSUNAnswer 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 GMTelliselkinsComment by $$anonymous$$ on $$anonymous$$'s answer
http://answers.unity.com/comments/598148/view.html
thanks for that, was so disappointed with unity :)Mon, 16 Dec 2013 18:48:41 GMT$$anonymous$$Comment by chris.weigle on chris.weigle's answer
http://answers.unity.com/comments/598070/view.html
No, that's just due to the default ToString format for float.
Try:
Debug.Log ("Vector2.right * 0.049 = " + (Vector2.right * 0.049f).ToString("R"));Mon, 16 Dec 2013 16:48:20 GMTchris.weigleComment by $$anonymous$$ on $$anonymous$$'s answer
http://answers.unity.com/comments/598066/view.html
In case anyone else looking for more details I've found out that Unity zeros all vectors shorter than 0.05f.
Just try this: Debug.Log ("Vector2.right * 0.049 = " + Vector2.right * 0.049f); results in a zeroed vectorMon, 16 Dec 2013 16:42:41 GMT$$anonymous$$Answer 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