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 /
  • Help Room /
avatar image
1
Question by Payton-Dugas · Jul 17, 2019 at 09:48 AM · rotationtransformquaternionangleeulerangles

Quaternion Rotation - AngleAxis/EulerAngle

I ran this simple script to try to grasp rotation manipulation. I've read tons of forms, so I kind of have an idea how things are done, but his straight up doesn't make sense. I was under the impression AngleAxis rotations would basically stack that way you could preform rotations in a specific order. That doesn't appear to be the case, but I have to be doing something wrong.

 if (Input.GetKey(KeyCode.Space))
         {
             transform.localRotation = Quaternion.AngleAxis(45, Vector3.forward);
             transform.rotation = Quaternion.AngleAxis(90, Vector3.right);
         } 

I'd like to assume after this runs the cube would have the orientation of (90,0,45), but it's just (90,0,0). Why? Is there any way to get that effect?

Original orientation cube was standing up on end alt text

Next I ran this code bit, and it also doesn't seem to do what's intuitive.
It appears the cube rotated (90, 45, 0). When running the code with x and y switched we reach the exact same effect.

 if (Input.GetKey(KeyCode.Space))
         {
             transform.localRotation = Quaternion.Euler(90, 0, 45);
         }


Original orientation cube was standing up on end alt text

In conclusion when running any of these rotation commands separate the outcome I expect is indeed the result, but when you change more than one Axis... forget it. An explanation or pointer towards some reference would be perfect.

capture0.png (104.9 kB)
capture2.png (106.5 kB)
Comment
Add comment · Show 4
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 Owen-Reynolds · Jul 17, 2019 at 04:48 PM 0
Share

Perfor$$anonymous$$g rotation in a specific order looks like: transform.rotation = Q1 * Q2;. It's confusing since star is repurposed as the "combine rotations" symbol. It's not multiplication -- it's more like how "cat"+fish" repurposes plus. Why don't we use Q1.combinedWith(Q2)? Because mathematicians use star.

Turn that 45 and 90 into Inspector variables, Play, and slide them around. Then flip the equation: transform,rotation=(flip them around the *). That should give a good feel.

To see why setting local shouldn't be the way to do it, suppose you needed to combine 4 rotations. We don't want to set transform.double-local and triple-local. transform.rotation=Q1*Q2*Q3*Q4; is simpler.

avatar image Bunny83 Owen-Reynolds · Jul 17, 2019 at 05:33 PM 0
Share

Uhm, no. Quaternion multiplication is just multiplication, nothing fancy. It's litterally just multiplication. Quaternions are just an extention of the complex numbers. Or do you want to say that complex number multiplication isn't multiplication as well?


Q1*Q2 is just (Q1.w + Q1.x*i + Q1.y*j + Q1.z*k) (Q2.w + Q2.x*i + Q2.y*j + Q2.z*k). Of course the only additional thing you have to remember is how the imaginary units i, j and k multiply together. i² = j² = k² = i*j*k = -1. Note that quaternion multiplication is not commutative. So while i j == k. When you do j * i you get -k.


The only thing that is a bit off is multiplying a quaternion by a vector. What you actually have to do to rotate the vector is to do Q1 V1 Q1conj where Q1conj is the complex conjugate. Though Unity combines this into a single multiplication Q1 * V1.

James Grime did a great job explaining the basics of quaternions. If you want to know more about them. watch the 3blue1brown videos on quaternions.

avatar image Bunny83 Bunny83 · Jul 17, 2019 at 05:44 PM 0
Share

Here's the actual quaternion multiplication how it's implemented in Unity. Right below is the quaternion-vector multiplication.

Show more comments

2 Replies

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

Answer by Bunny83 · Jul 17, 2019 at 03:43 PM

localRotation and rotation describe both the same rotation, just in different coordinate spaces if the object actually is a child of another object. If there's no parent object then localRotation and rotation are exactly the same thing. When you set the rotation / orientation of an object you overwrite the old orientation with the new one.


If you want a relative rotation you have several options:

  • First the simplest one is to use the Rotate method. It allows you to perform a relative rotation on an object either based on the axis aligned relative euler angles, or by specifying a rotation axis and a relative angle. Note that the Rotate method has an optional parameter to specify the coordinate space in which you want to rotate (world space or local space).

  • Another way is to use quaternion multiplication. You setup a quaternion rotation and muliply the objects current rotation by that quaternion

Something like that:

 transform.rotation *= Quaternion.AngleAxis(90, Vector3.right);

If you want to know more about quaternions have a look at this numberphile video and / or this 3b1b video

Comment
Add comment · Show 2 · 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 Payton-Dugas · Jul 17, 2019 at 11:12 PM 0
Share

Got it. I was missing the *=. Literally thank you so much!

avatar image Bunny83 Payton-Dugas · Jul 17, 2019 at 11:18 PM 0
Share

Note that x *= y; is just a shorthand for x = x * y;

avatar image
0

Answer by GhostlyFedoras · Jul 17, 2019 at 10:39 AM

Honestly I don't know anything about Quaternions though this might be helpful, https://docs.unity3d.com/ScriptReference/Quaternion.Euler.html

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

168 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 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

Questions about Rotations in unity 1 Answer

Why isn't my steering wheel working? 0 Answers

Change angle of a moving object but maintain direction of movement? 0 Answers

Rotation problem 0 Answers

How to use Quaternion.Slerp with transform.LookAt? 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