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 /
  • Help Room /
avatar image
1
Question by Glabrezu · Jan 27, 2016 at 01:23 AM · rotationquaternioneulerangles

Quaternion.Euler doesn't work right?

This seems wrong:

     Quaternion DesiredRot = Quaternion.Euler(90f, 0f, 0f);
     Debug.Log(DesiredRot.eulerAngles.x); // DISPLAYS 90
     
     Quaternion DesiredRot = Quaternion.Euler(100f, 0f, 0f);
     Debug.Log(DesiredRot.eulerAngles.x); // DISPLAYS 80. Why?
     
     Quaternion DesiredRot = Quaternion.Euler(110f, 0f, 0f);
     Debug.Log(DesiredRot.eulerAngles.x); // DISPLAYS 70. Why?
     
     Quaternion DesiredRot = Quaternion.Euler(120f, 0f, 0f);
     Debug.Log(DesiredRot.eulerAngles.x); // DISPLAYS 60. WHY...?

And the documentation says the params should come in a different order, yet that's how it works.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by Glabrezu · Jan 27, 2016 at 11:15 PM

Found an article about Quaternions.

If anyone else has this problem, you can't just assign a rotation to a Quaternion apparently. You take your initial Quaternion and then multiply it by the second one, which should contain the rotation which you want to apply to the first one.

So you should basically do it like that:

     Quaternion initialRot = objToRotate.transform.rotation;
     objToRotate.transform.rotation = initialRot * Quaternion.Euler(90f, 0, 0);

This example just rotates the object by 90 degrees.

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 Mizdotexe · Aug 24, 2021 at 03:30 PM 0
Share

Can someone explain why this works please?

avatar image
0

Answer by DiegoWw · Jul 12, 2019 at 02:50 PM

@Glabrezu is correct. Additionally, you can "kinda" assign an Euler angle by doing:

objToRotate.transform.rotation = Quaternion.Identity * Quaternion.Euler(90f, 0, 0);

Comment
Add comment · Show 3 · 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 zukahara · Apr 13, 2020 at 10:27 PM 0
Share

It's an old post but maybe will somebody anwser :)

Im working with Rotations in unity, had the same problem and found this discussion.

Sorry, but for me does the correct answer no sense.

$$anonymous$$y thoughts: Fakt is that:

 Quaternion.Identity * Quaterion.Euler(45f, 45f, 45f) ==  Quaterion.Euler(45f, 45f, 45f) 

Because of the property of Identity

I. e. my Initial Rotation is the Identity. Consequently:

 Quaternion DesiredRot = initialRot * Quaternion.Euler(100f, 0f, 0f);

Is equal to Quaternion.Euler(100f, 0f, 0f).

$$anonymous$$y Question is: Why shows this

Debug.Log(DesiredRot.eulerAngles.x);

80° ins$$anonymous$$d of 100°? I did some tests with Quaternion.Euler(100f, 0f, -45f); converted Euler(100, 0, -45) to Quaternion, back to Euler and i will get (80.0, 180.0, 135.0). That's equal to an euler rotation of (-100, 0, -45) and that isn't right. Quaternion qTest= Quaternion.Euler(100f, 0f, -45f); Debug.Log(qTest.eulerAngles); I think there is a bug or I'm wrong? :)
avatar image streeetwalker zukahara · Apr 14, 2020 at 07:26 AM 0
Share

@zukahara, if you:

  Debug.Log( Quaternion.Euler( 100f, 0, 0 ).eulerAngles  );
 
  You see printed:     (80.0, 180.0, 180.0)
  Those are two different representations of 
   exactly the same set of rotations



Remember that the order of Rotations matters. So first rotating x by 100, and then y by zero, and finally z by zero, ends up the same thing rotating x by 80, and then y by 180 and then z by 180.

To say that the Quaternion calculation is wrong because, "it took my 100 degrees and now it's 80 degrees" is a mistake in your thinking about it. You have forgotten to apply the rotations on the the other two axes.:

For any given set of rotations, there may be more than one set of equivalent rotations.

 Debug.Log( Quaternion.Euler( 100f, 0f, -45f ).eulerAngles );
 
 Yields:     (80.0, 180.0, 135.0)
 
 And Debug.Log( Quaternion.Euler( 80.0f, 180.0f, 135.0f ).eulerAngles );
 
 Yields:   (80.0, 180.0, 135.0)
 
 Go figure!  Once in Quaternion form, the representation has been optimized.

:

The important thing in Unity is to trust Quaternions and deal with Euler angles as little as possible. Do not convert from Eulers to Quaterinons and back to Eulers and Back to Quaternions in order to clamp rotations, or other operations. You can drive yourself crazy!:

Quaternions were invented by William Hamilton nearly two hundred years ago based on the mathematics of Leonhard Euler from a hundred years earlier. The are mathematical constructs that have been proven. They are perfect, as such constructs are.:

There are no bugs in Unity's Quaternion class!

avatar image DSivtsov streeetwalker · Aug 24, 2021 at 10:35 PM 0
Share

The little correction to @streeetwalker

Remember that the order of Rotations matters. So first rotating x by 100, and then y by zero, and finally z by zero, ends up the same thing rotating x by 80, and then y by 180 and then z by 180

But it nothing change, He is absolute right

Transform.localEulerAngles ...

In Unity these rotations are performed around the Z axis, the X axis, and the Y axis, in that order.

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

49 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

Related Questions

How to convert Quaternions to Euler angles with different order? 0 Answers

If rotation was over 20° smoothly rotate towards the next 90° 2 Answers

Help with suns rotation 0 Answers

Instantiate object in orientation of previously instantiated object 1 Answer

Rotation Problem on X Axis over 90 and -90 degrees! 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