- Home /
Reverse rotations problems...
Hi,
I've been trying to figure this out and I just can't get it to work, so hopefully one of you guys can get it working.
All I need to do is be able to reverse rotations. Example: When a storm starts I have the wind zone rotate to 180 degrees, then stop once it reaches 180. Once a storm has cleared up I want the winds rotation to gradually return to 0 degrees, but this requires reverse rotations. If I use the normal transform.rotate I get the gimbal lock problem. If anyone knows how that'd be great, I just need an example that's all.
Also I've tried using inverse quaternions and I'm not sure how to properly set up my object so this could also be an approach.
windZone.transform.rotation = Quaternion.Inverse(target.rotation);
I'm using the below to lock the rotation once reached with an if statement, which I read could cause problems, but I'm not sure if they're related to the gimbal lock.
windZone.transform.eulerAngles.y = 0;
If anyone has any solutions I'm willing to try anything and I'll be sure to mark as answered if it works.
Answer by BHS · Mar 13, 2012 at 03:37 AM
Thanks everyone for the answers, but I ended up finding a better solution after much searching and trial and error.
It was as simple as transform.Rotate(-Vector3.up * "Whatever") which worked great and did exactly what I needed.
That's also the same as transform.rotate(0,-whatever,0);
The tricky part is doing it over several frames and stopping at the correct spot, which Lerp and rotateTowards can simplify.
Answer by Esa · Mar 12, 2012 at 06:08 AM
You could Mathf.Lerp or the Mathf.LerpAngle the rotation value back. I have not used LerpAngle myself ever, always done it with just Lerp
.
LerpAngle
knows that you can go from 270 to 0 by adding 90 degrees (Lerp will subtract 270, rotating the long way.)
Also take a look at Quaternion.RotateTowards
and Quaternion.Lerp
. For example, you could save your starting wind with: Quaternion windRestAngle = transform.rotation;
, then Lerp/$$anonymous$$ove back to it when done.
One thing to watch for, going exactly 1/2 a circle (180 to 0) can rotate "over the top" or around, or under the bottom. If you go from 0 to 179.9, it always picks the shortest distance -- around.
Your answer
Follow this Question
Related Questions
Yaw Pitch Roll order? 0 Answers
Why Is Object Rotation Resetting After 90 or -90 Degrees 0 Answers
Avoiding Gimbal Lock 1 Answer