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 waterdog · Oct 09, 2013 at 10:18 AM · rotationmousequaternionflythrough

Why does only the first of sequential quaternion operations work?

This is an add on to my previous question about camera flipping with the first mouse move. The solution there works, but, having to resort to compensating torque feels a little dirty. So, I've been fiddling with quaternions again. I have a code segment that works for rotating the camera around the X axis and another that works for rotating the camera around the Y axis, but, if I put the code segments in sequence, only the first one works. The axis that follows seems frozen. Switching the order changes which axis is frozen. This happens even with both segments in LateUpdate(). And, if one segment is in Update() and the other is in LateUpdate() then the one in LateUpdate() succeeds. Is there some reason why one quaternion operation locks out a following quaternion operation? The code segment follows:

 if (!firstpass) {
                 
   // Do Y operations:    
                 
   rotationY += Input.GetAxis("Mouse Y") * cameraSensitivity * Time.deltaTime;
   while (Mathf.Abs(rotationY) > 360) {
     rotationY = (Mathf.Abs(rotationY) - 360) * Mathf.Abs(rotationY)/rotationY; // abs * sign
   }
   rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
   Quaternion quaternionY = Quaternion.AngleAxis(rotationY, Vector3.right); 
   transform.localRotation = initialRotation * quaternionY;    
             
   // Do X operations:
                 
   rotationX += Input.GetAxis("Mouse X") * cameraSensitivity * Time.deltaTime;
   while (Mathf.Abs(rotationX) > 360) {
     rotationX = (Mathf.Abs(rotationX) - 360) * Mathf.Abs(rotationY)/rotationY; // abs * sign
   }
   rotationX = Mathf.Clamp (rotationX, minimumX, maximumX);
   Quaternion quaternionX = Quaternion.AngleAxis(rotationX, Vector3.up);
   transform.localRotation = initialRotation * quaternionX;                 
 
 } else {
                 
   initialRotation = transform.localRotation;
 
   rotationX = 0;
   rotationY = 0;
                 
   firstpass = false;    
 
 }


 
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by wibble82 · May 01, 2014 at 09:30 AM

Hi

I can't guess off the top of my head exactly whether your calculations are correct, but there's definitely a problem there. You basically go:

  • do some calculations for Y

  • set my rotation based on those calculations

  • do some calculations for X

  • set my rotation based on those calculations

So the 2nd step always overrides the first. You might removing line 11 altogether, then changing line 21 to:

transform.localRotation = initialRotation quaternionX quaternionY;

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 waterdog · Aug 14, 2015 at 06:29 AM 0
Share

DOH! Thanks! Finally back around to this project. That was it, of course.

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

16 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

Related Questions

Keep objects current rotation, with Input Mouse X 0 Answers

LookTo Rotation Mouse Drag 2 Answers

How do I rotate Z axis based off mouse click and drag? 2 Answers

How to Change rotation while preserving local horizontal rotation 1 Answer

Rotate object following mouse movement. Object jumps/ flips 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