Normalize Angles for Quaternion to Euler
Sometimes when you work with EulerAngles some rotations can miss because unity do not block the rotation at 360, this are two simple extensions to get the normalized angles and use that insted:
public static Vector3 NormalizeAngles (this Vector3 angles)
{
angles.x = NormalizeAngle (angles.x);
angles.y = NormalizeAngle (angles.y);
angles.z = NormalizeAngle (angles.z);
return angles;
}
public static float NormalizeAngle (this float angle)
{
while (angle>360)
angle -= 360;
while (angle<0)
angle += 360;
return angle;
}
Related protips:
Written by Bruno Mikoski
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Unity
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#