Problem with X-axis rotation

I made 3 sliders to rotate the object along the axes, the slider values are from 0 to 360
Rotation on the Y and Z axes works fine, but rotation on the X axis does not work correctly
At some point, I get a 180 degree rotation on the Y and Z axes when rotating on the X. At the same time, the rotation methods are exactly the same and I don’t have any special settings for the X-axis, it just doesn’t rotate the way I expect

        public void OnXRotationChanged(float value)
        {
            currentObject.Rotation = Quaternion.Euler(value, currentObject.Rotation.eulerAngles.y, currentObject.Rotation.eulerAngles.z);
            Debug.Log(currentObject.Rotation.eulerAngles);
        }

        public void OnYRotationChanged(float value)
        {
            currentObject.Rotation = Quaternion.Euler(currentObject.Rotation.eulerAngles.x, value, currentObject.Rotation.eulerAngles.z);
        }
       
        public void OnZRotationChanged(float value)
        {
            currentObject.Rotation = Quaternion.Euler(currentObject.Rotation.eulerAngles.x, currentObject.Rotation.eulerAngles.y, value);
        }

Is there some actual problem with the orientation or are you just confused by the displayed euler angles in the inspector? There is multiple solutions when converting between quaternions and euler angles.

The bottom line is that it’s not just the display in the inspector
My object starts to flip suddenly while I’m moving the slider
According to my logs, the following happens
(x:57, y:0, z: 0)
(x:58.3, y: 180, z: 180) (x:59.2, y:180, z: 180)
(x: 60, y:0, z:0)
This behavior simply flips the object as well changes its rotation on other axes, it looks like the object is sausage.

You can’t read back from .eulerAngles in the general sense.

Track your own value in a float, adjust it, clamp it, use it to make new rotations.

Here’s why:

All about Euler angles and rotations, by StarManta:

https://starmanta.gitbooks.io/unitytipsredux/content/second-question.html

In one of my projects I had a complex setup of rotating bones within a blender model. Here is all the relevant snippets(I think):

[Header("Right Leg")]
    [Range(0, 230)] // 165 straight
    public float rightLegRotX;
    [Range(-60, 80)]
    public float rightLegRotY;
    [Range(-90, 20)] // inverse of left
    public float rightLegRotZ;
    Quaternion rightLegRot;
  
    void RightLegRotations()
    {
        SetInstantRotation(rightLeg, rightLegRot, rightLegRotX, rightLegRotY, rightLegRotZ);
        SetInstantRotation(rightShin, rightShinRot, rightShinRotX, rightShinRotY, rightShinRotZ);
        SetInstantRotation(rightFoot, rightFootRot, rightFootRotX, rightFootRotY, rightFootRotZ);
        SetInstantRotation(rightToe, rightToeRot, rightToeRotX, rightToeRotY, rightToeRotZ);

        rightLegRot = rightLeg.transform.localRotation;
        rightShinRot = rightShin.transform.localRotation;
        rightFootRot = rightFoot.transform.localRotation;
        rightToeRot = rightToe.transform.localRotation;
    }
  
    void SetInstantRotation(GameObject bone, Quaternion modRot, float X, float Y, float Z)
    {
        Quaternion check = Quaternion.Euler(X, Y, Z);

        if (modRot != check)
        {
            //print($"{bone} set rotation");
            bone.transform.localRotation = check;
        }
    }

So not sure if anything in that can help spark a new idea, or give a fix for your situation. :slight_smile: