Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 F1R3HAWK · Sep 03, 2019 at 03:36 PM · rotation axislocalrotation

LocalEulerAngles

I wrote a simple sphere rotation script, that allows my sphere to rotate by x and y axis. The problem is that I using transform.localEulerAngles and it doesn't seem to work properly. It looks like it is using global X and Y axis instead of local.

 rotateGO.localEulerAngles = new Vector3(pitch, yaw, 0.0f);


P.S. found an answer https://answers.unity.com/questions/358731/localeulerangles-changes-global-angles.html but it only works with the Y axis. Is there any other way to do this?

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 Bunny83 · Sep 03, 2019 at 05:38 PM

Many people have the wrong idea about local spaces. The localEulerAngles specify the orientation of the object in the local space of the parent object, not relative to the objects own local space. This wouldn't even make any sense since the orientation of the object in it's own local space is always (0,0,0). Positions and rotations always have to be relative to some reference frame. Ultimately that's always the worldspace.


If an object doesn't have a parent the local and global position / rotation is the same. Euler angles specify the rotation of an object by carrying out 3 consecutive rotations on the object in a particular order. However there's no general valid order and there are 6 different arrangements. Unity's euler angles uses the order Y-X-Z around "local axis" or expressed in parent space it's the other way round Z-X-Y. From a global point of view the outermost gimbal is the y axis and the next one is the x axis. It seems what you want is the other way round. So you want to specify the x axis first and have rotate y relative too the x rotation.


Note that euler angles always specify absolute rotations. So they can not be used to rotate an object relative to it's current rotation. Keep in mind that if you want to allow actual relative rotation around two local space axis, the object will automatically rotate around z as well. Imagine you have an object that isn't rotated initially. If you first rotate 90° upwards around the x axis the object faces up. Now rotate 90° around the new local y axis to the right so the object is now looking right but tilted 90° clockwise. If you rotate back 90° around the local x axis you are back to the original direction but your object is still tilted 90° clockwise around local z. So without ever rotating around the z axis you end up with a z rotation. It's a bit like this just to visualize the effect better ^^.


So if you want to specify absolute rotation euler angles you have to know what rotation order you want. If the default order is not what you want, you can use a second intermediate gameobject which acts as seperate additional gimbal. That way you can rotate the parent on a certain axis and the child on another axis.


If you actually want to freely rotate with relative rotations (be aware of the implicit rotation around the third axis) you just can use two seperate calls of Rotate with the axis you want to rotate around.

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

109 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 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 avatar image

Related Questions

Can't figure out local rotation axis. 1 Answer

Quaternion lerp is not rotating my object to the desired rotation? 1 Answer

Rotating CharacterController around object pivot when character controller has offset? 0 Answers

Finding a local position matching a global position in an individually rotated hierarchy 2 Answers

lookAt on the x axis, without the 180°turn! 3 Answers


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