I am trying to set up a slider (that starts at 0.5) that can be used to rotate around the x axis (-180 to + 180). I am not fully understanding how rotation works, however.
Here is my code
//percent is the value of the slider
float angle = 180;
float rotation = ((angle * 2) * percent) - angle;
transform.localRotation = Quaternion.Euler(rotation, transform.localEulerAngles.y, transform.localEulerAngles.z);
Since I will be adding sliders for the y and z rotation as well, I don’t want them to be affected by the x slider. The code above doesn’t work. It produces a seemingly random angle while sliding the slider.
EDIT:
Doing this code below seems to output strange results.
Vector3 vec = new Vector3(rotation,0,0);
vec = Vector3.Scale(transform.localEulerAngles, new Vector3(0,1,1)) + vec;
transform.localEulerAngles = vec;
Debug.Log(rotation + " " + transform.localEulerAngles);
The log then outputs (going from -180)
-180 (0, 180, 180)
-168 (348,0,0)
-156 (336,180,180)
-144 (324,0,0)
-132 (312, 180,180)
-120 (300,0,0)
-108 (288,180,180)
-84 (276,0,0)
… (the rest are actually correct)
What is happening? Why is Y and Z rotation getting set to 180? Why is the X inaccurate? It appears anything not in the range of -90 to 90 screws up. Why???