• 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 pluspluspinata · Jun 14, 2017 at 09:52 AM · quaternionrotation axis

Locking rotation WORLD Z AXIS (Quaternions are shaving years off my lifespan)

Spent half a day trying to figure this out but am still stuck. I am positive this is shaving some years off my lifespan. How do I lock the WORLD Z AXIS rotation of my object while allowing LOCAL X & Y & Z rotation of the object?

The euler rotation of my z axis will no longer be 0 once the y and x axis are moved, so it is not possible for me to lock the euler angle of my z axis to 0.

To lock the WORLD Z AXIS rotation of my object, do I have to learn quaternion mathematics and manually restrict the w,x,y,z values?

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 · Jun 14, 2017 at 10:19 AM

If you allow relative rotations it's not possible since you can reach any rotation by just using two local rotations. Example:

90° on local X --> you're looking up
90° on local Y --> you're looking sideways
-90° on local X --> you're looking the same initial direction but you are rotated 90° around Z even you never rotated around Z

The only way to avoid rotation around one axis is to use absolute rotations. Actually there is nothing like a world-z-rotation axis since the rotation axis of euler angles always depend on each other since their rotations are executed one after another.

The order of the rotations matters. Unity's euler angle order is:

Y degree around local Y
X degree around local X
Z degree around local Z

This is the same as doing the rotations around world axis but in reverse order:

Z degree around world Z
X degree around world X
Y degree around world Y

Using absolute X and Y rotations is common for most FPS camera controls since you always want the view up-right. For this you would simply use two float variables to specify the current X and Y rotation and simply use Quaternion.Euler with the two variables. You would use the mouse delta input to change those two variables. That way your camera rotation is always defined by an absolute rotation around X and Y.

edit
Unity's MoustLook script can do this with the right gameobject setup. Usually the player object should only rotate around the Y axis (turn left and right). Then you would have the camera as child which will only rotate around the local X axis (up and down). So you have a kinematic chain. You would place one MouseLook script on the player object and only allow mouseX rotation. On the child camera you use another MouseLook script and only allow mouseY rotation.

In games like Space Engineers where you actually float in space you actually have / need an additional control axis (usually Q and E) to rotate around local Z. In space there is no concept of "up" or "down". Everything is relative.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

67 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

Related Questions

Locking rotation makes object spin 0 Answers

How to rotate object in a few axis in turn 0 Answers

Rotation changing in untouched axis 1 Answer

Track Quaternion local Y axis to position 1 Answer

Rotate 2d Sprite 0 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