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
1
Question by Brain-_-Fail · Jan 21, 2017 at 06:45 AM · camera rotaterotate objecteuleranglesrotation axis

Transform.Rotate() rotation about one axis also rotates about the other axes

Hello , i'm new to learning unity and infact game development.Below i have setup a scene to learn about unity and i have encountered a strange problem that doesn't comply with anything that unity has documented.!

alt text

I am rotating the camera (which is a child of my capsule game object, The object with Gradients highlighted in the photo, Capsule game object is a child of nothing) according to the user mouse movements.Here is the code i have written(Please ignore the commented lines for now)

       Vector3 a;
             rotateby = Input.GetAxis("Mouse X") * MouseSensitivity;// Rotate by is a float variable
             rotation.Set(0, rotateby, 0); // Rotation is a Vector3 i've declared
             transform.Rotate(rotation, Space.Self);                                    
 
         /*       a = transform.localRotation.eulerAngles;
                  a.Set(0, transform.eulerAngles.y, transform.eulerAngles.z);
                  transform.eulerAngles = a;        
         */    
 
             
             rotateby = Input.GetAxis("Mouse Y");
             if (!invertY) { rotateby = -rotateby; }
             rotation.Set(0, 0, rotateby);
             transform.Rotate(rotation, Space.Self);
             
 
         /*       a = transform.localRotation.eulerAngles;
                  a.Set(0, transform.eulerAngles.y, transform.eulerAngles.z);
                  transform.eulerAngles = a;
         */

As you can see from the code when the user moves the mouse across Horizontal axes , i'm only updating the angle of rotation across the capsule's y-axis( rotation.Set(0, rotateby, 0) ) without updating the other two angles(x and y), which rotates it across its y axis.Similarly when the user does vertical mouse movement i'm updating only the z-angle of the capsule( rotation.Set(0, 0, rotateby) ) without updating the other two angles(x and y) again, so now it rotates across it's z-axis.Now it does what is expected, it is infact rotating across its z and y axes but it is also rotating across the x-axis in some cases.I am monitoring the values of the three angles(x y z) from the inspector.Look at how the capsule is titled towards the right , across its x-axis and also from the inspector below(look at the x-angle = -35)alt text

Now the commented lines of code are a solution to this problem of rotating around the x-axis(as when the x-angle changes i'm again setting it to 0).But what i need to know is what have i done wrong in my code i'm never modifying the x-angle then why is it changing to -35??.I have read about local vs GlobalSpaces again and again but i can't find the answer to this.Also what i think is that it's not a Gimbal Lock because as the parenting order that unity uses is Z-->X-->Y.So Gimbal lock could only occur if i rotate around the X-axis(Which i am not doing in my code) thereby aligning the Y-axis with the Z-axis.Why is this behaviour occuring, why is it rotating around its x-axis .Please Correct me if i am wrong, this is a barrier to my learning process cause i can't continue without clearing my concepts.

Thankyou, much obliged !

UPDATE: I have tried changing the 2nd parameter in transform.Rotate() method to Space.World , the problem of rotation about x-axis still happens but in some different mouse movement order.

1.png (292.5 kB)
3.png (291.7 kB)
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
3
Best Answer

Answer by Brain-_-Fail · Jan 23, 2017 at 01:00 PM

Ok i got the answer to this problem here :

https://gamedev.stackexchange.com/questions/136174/im-rotating-an-object-on-two-axes-so-why-does-it-keep-twisting-around-the-thir/136175#136175

infact this was a response to this same question that i posted on gamedev.stackexchange :

http://gamedev.stackexchange.com/questions/136083/transform-rotate-rotation-about-one-axis-also-rotates-about-the-other-axes?noredirect=1#comment238896_136083

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Why is this rotation not performed as expected? 1 Answer

Rotate camera smoothly on android 1 Answer

Issue rotating objects with input from the mouse wheel 1 Answer

LookRotation freaks out.. 2 Answers

Smoothly rotate object based on GetAxis 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