Frame lock
What you see is called gimbal lock more here . This happens when Euler angles intersect a plane of 360 or more specifically (two of the three axes are in parallel configuration), and that is why people use Quaternions.
Quaternions
You should not hide the corners of the eulers directly. I would recommend something like this:
Quaternion q = Input.gyro.attitude.rotation;
Using Quaternion and not Euler angles, we will avoid locking the universal joint and, therefore, avoid the problem with 360, 0.
If you just want to show the angle in which they are facing in the y direction, I could recommend something like this, this will wrap the angle y to 0 to 180 degrees:
/// <summary> /// This method normalizes the y euler angle between 0 and 180. When the y euler /// angle crosses the 180 degree threshold if then starts to count back down to zero /// </summary> /// <param name="q">Some Quaternion</param> /// <returns>normalized Y euler angle</returns> private float normalizedYAngle(Quaternion q) { Vector3 eulers = q.eulerAngles; float yAngle = eulers.y; if(yAngle >= 180f) { //ex: 182 = 182 - 360 = -178 yAngle -= 360; } return Mathf.Abs(yAngle); }
source share