I have a slider that I use to choose how much I want the object rotated between -180 to 180. Using this code below makes rotation on the X axis possible:
HOWEVER, I want the X rotation on the localRotation to be the only one that changes. Y and Z rotations should be completely unaffected. On top of that, X should reset the X rotation before setting the new X rotation, or else the slider would add the value as you slide it, instead of indicating the value.
Using Eulers does not work! Anything not between -90 to 90 gives me unpredictable results, changing the Y and Z rotations to 180, and doing other weird stuff I don't fully understand.
How do I reset ONLY the x rotation, then set ONLY the x rotation with the newly calculated x rotation???
The Y and Z changing is not really something you can prevent, if you're talking about the euler angle values. Rotations are stored as quaternions, and there's more than one valid way to represent a rotation as a euler angle (for example, 0, 0, 0 is the same as 180, 180, 180). However, you can simply keep track of it yourself...assuming you have a float called xRotation, use this in OnGUI:
Save your original facing:
You already have the desired x rotation set up, in
Last step is to say your new rotation is your starting, with the additional X-rotation added on:
o That says to start at your original facing F and "apply" the local x-tilt. Star is redefined for quaternions to mean "rotate like this, then from there like this."
o If you flip the order:
answered Jul 17 '12 at 08:53 PM
Sounds like a job for Slerp(). Given two rotations and a float between 0 and 1, slerp will produce a new rotation X% between the other two. It's the same principle as lerping (linear interpolation), which will probably be an easier search term if this is a new topic for you.
answered Jul 17 '12 at 07:13 PM