|
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???
(comments are locked)
|
|
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: Please read my question before answering. This RESETS Y and Z rotations to 0 (or switches them to 180). I want the Y and Z rotations to be left untouched. I know messing with the Eulers generally provides these types of results, which is why I want to use Quaternions.
Jul 17 '12 at 09:19 PM
DoctorWhy
I did read your question. Just add in the Y and Z values (which should also be your own variables, since you can't read from euler angles reliably) rather than using 0, 0, which was just an example in order to focus on how to set the X rotation.
Jul 17 '12 at 10:32 PM
Eric5h5
But if the Y and Z are 0 (I haven't tested any other values yet), they will get changed to 180 if you go out of the -90 to 90 bounds. I want them to STAY 0. Could I reliably do that using transform.localEulerAngles?
Jul 17 '12 at 10:46 PM
DoctorWhy
No, if you assign 0 to your Y and Z variables, they won't somehow change. The Y and Z values in the inspector probably will, but that won't be relevant, since you wouldn't read those values anyway. Your "internal" rotation values will be stored by you in your own variables, so will always be consistent.
Jul 17 '12 at 10:56 PM
Eric5h5
Ah, ok... It worked. See... I thought I tried this, but I guess I only tried just the X and noticed the y and z changing and thought it wouldn't work. Sorry if I seemed a bit short tempered... rotation was harder in Unity than any other libraries or game engines I have ever used. Thanks for the help!
Jul 18 '12 at 03:07 AM
DoctorWhy
(comments are locked)
|
|
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: NOTES: 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 o If you flip the order: Doesn't this rotate from the old x rotation??? I don't want to ADD to the old X rotation, I want the new X rotation EXACTLY equal to the new X rotation without touching the old Y and Z rotation.
Jul 17 '12 at 09:15 PM
DoctorWhy
(comments are locked)
|
|
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. This is still going to Slerp to the X rotation being correct but the Y and Z rotation resetting, is it not?????? I need JUST X to change, not Y or Z
Jul 17 '12 at 07:40 PM
DoctorWhy
(comments are locked)
|
