Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 homer_3 · Jul 23, 2016 at 05:51 PM · quaternionmathgimbal-lock

Gimbal lock hell even with quaternions?

I'm trying to make some flight controls and I think I'm running into gimbal lock issues since my camera view is periodically flipping out. I'm using quaternions as much as I can though, so I thought I wouldn't run into this issue. Specifically, I'm trying to change the roll and yaw and my camera will regularly spin around like crazy for a few frames, ultimately settling back into the correct position. My code is

 float tarRollAngle = -tarAngle;
 float tarYawAngle = tarAngle;
 //Only update tar angle if it's changed enough
 if(Mathf.Abs(rotateRollTarAngle - tarRollAngle) > 5)
 {
     rotateRollTarAngle = tarRollAngle;
     rotateRollStartTime = Time.time;
     rotateRollStartAngle = Globals.cockpit.transform.localRotation.eulerAngles.z;

     rotateYawTarAngle = tarYawAngle;
     rotateYawStartTime = Time.time;
     rotateYawStartAngle = Globals.cockpit.transform.localRotation.eulerAngles.y;
 }
 Quaternion yawRot = Quaternion.AngleAxis(Mathf.Lerp(rotateYawStartAngle, rotateYawTarAngle, (Time.time - rotateYawStartTime) * rotSpeed), Vector3.up);
 Quaternion rollRot = Quaternion.AngleAxis(Mathf.Lerp(rotateRollStartAngle, rotateRollTarAngle, (Time.time - rotateRollStartTime) * rotSpeed), Vector3.forward);
 Globals.cockpit.transform.localRotation = yawRot * rollRot;


edit: I think the issue is actually caused by accessing the z and y angles from the rotations for my start angles. It's not accounting for the fact that I can get something like 357 instead of -3.

Comment
Add comment · Show 4
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 Eno-Khaon · Jul 23, 2016 at 06:01 PM 0
Share

What values are you seeing in your tarYawAngle and tarRollAngle variables? If they're staying within a maximum 360-degree angle range (whether 0 to 360 or -180 to 180 or similar), then the problem actually lies in the implementation of AngleAxis using Lerp.

Otherwise, if the values continue to rise or fall endlessly while rotating, then the problem lies elsewhere.

avatar image homer_3 Eno-Khaon · Jul 23, 2016 at 06:18 PM 0
Share

The angles stay between -90 to 90. I have no idea how I could lerp from one angle to another without AngleAxis though.

avatar image Eno-Khaon homer_3 · Jul 23, 2016 at 09:04 PM 0
Share

Rather than reading in your rotation regularly, it would probably be best to keep track of your rotation yourself and implement them manually.

For example, it could look something like this:

 float curRollAngle; // Your current rotation maintained explicitly
 
 // ...
 
 rotateRollTarAngle = tarRollAngle; // unchanged
 rotateRollStartTime = Time.time; // unchanged
 rotateRollStartAngle = curRollAngle;
 
 Quaternion rollRot = Quaternion.AngleAxis($$anonymous$$athf.Lerp(rotateRollStartAngle, rotateRollTarAngle, (Time.time - rotateRollStartTime) * rotSpeed), Vector3.forward); // unchanged

Really, I only added one line and changed another. Elsewhere in your script, however, you would need to properly define a value for the current angle. Either way, the only important detail is that, rather than getting the starting rotation from the object's rotation, keep track of the value yourself. Then you'll always know what the value will be.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

54 People are following this question.

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

Related Questions

[SOLVED]aligning rigidbody to be "level" with world's X and Z coords. How can I make sure it faces the same way (Y coord)? 0 Answers

Quaternion using global values instead of local. Please help :( 0 Answers

Gimbal Lock with Quaternions 0 Answers

Rotation of child object is different in play mode 0 Answers

Quaternion rotation issue 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