Hi,
I am working on an editor script, whenever the user changes an objects rotation, I store the rotation value in a variable. I know I shouldn’t read from Quaternion.eulerAngles but do I have any other option? When an angle is -10 eulerAngles returns it as 350 and I need store it as -10. What should I do?
I solved my problem by doing some math to extract the angles from Quaternion through a custom function. You can google and find the equations needed.
This is what standard asset MouseLook uses :
Quaternion ClampRotationAroundXAxis
(Quaternion q, float minAngle, float maxAngle)
{
q.x /= q.w;
q.y /= q.w;
q.z /= q.w;
q.w = 1.0f;
float angleX = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.x);
angleX = Mathf.Clamp(angleX, minAngle, maxAngle);
q.x = Mathf.Tan(0.5f * Mathf.Deg2Rad * angleX);
return q;
}