Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by BHS · Mar 12, 2012 at 04:20 AM · rotationquaternionreversegimbal-lock

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
-2
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Owen-Reynolds · Mar 13, 2012 at 03:07 PM 0
Share

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.

avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Owen-Reynolds · Mar 12, 2012 at 06:50 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Quaternion rotation flips axises when upside down 0 Answers

unwanted rotation on the y and z axes 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges