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
0
Question by blocker2176 · Apr 21, 2018 at 03:21 AM · quaternionmultiply

Multiplying quaternions and Multiplying quaternion with Vector3

Hey guys.

I'm having trouble understanding what multiplying quaternions with other quaternions and multiplying quaternions with Vector3 does. Could someone explain how it is different than adding the x, y, z Euler angles of one quaternion with another? Also a simple example of where in a game you would use this.

Thanks ,

Comment
Add comment · Show 1
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 ElijahShadbolt · Apr 23, 2018 at 02:06 AM 0
Share

A good example of its usefulness is when trying to replicate Transform.TransformDirection or InverseTransformDirection with rotations ins$$anonymous$$d of vectors, by using Transform.rotation.

 transform.TransformDirection(Vector3.forward);
 // same as
 transform.rotation * Vector3.forward;
 
 transform.InverseTransformDirection(Vector3.forward);
 // same as
 Quaternion.Inverse(transform.rotation) * Vector3.forward;
 
 // get world-space rotation of local-space euler angles (0, 45, 0)
 Quaternion newRot = transform.rotation * Quaternion.Euler(0, 45, 0);

The code above is untested.

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Firas4d · Apr 22, 2018 at 09:53 AM

Hi, Multiplying a quaternion with a vector is not problematic -unlike the quaternions multiplication- it simply results in a vector that is rotated by the given quaternion.

Now multiplying quaternions is the real deal, according to Unity's Scripting API multiplying quaternions will combine the rotations in-sequence. Take a look at the example below :

 Quaternion q1 = Quaternion.Euler(45, 0, 0);  
 Quaternion q2 = Quaternion.Euler(0, 45, 0);  
 Quaternion q3 = Quaternion.Euler(0, 0, 45);  
 Quaternion q4 = Quaternion.Euler(45, 45, 45);
 Quaternion c1 = q1 * q2 * q3;

Do you think q4 and c1 has the same rotation? the answer is absolutely not! However, if you just change the order of the operands by a little bit

 Quaternion c1 = q2 * q1 * q3;

then q4 and c1 rotations will be equal!

The whole point of quaternions is to solve a well known problem called Gimbal Lock which happens when dealing with 3 separate rotational axis values, the math behind it is complicated and isn't necessary to be fully understood to use quaternions in Unity. I found this answer to be a good starter to understanding quaternions.

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 blocker2176 · Apr 22, 2018 at 04:25 PM 0
Share

How did you know the correct order of the operands to get the same value as q4?

avatar image Bunny83 blocker2176 · Apr 22, 2018 at 11:18 PM 1
Share

Euler angles are 3 consecutive / seperate rotations. There are many different conventions in which order you may apply the rotations. Unity uses the local axis order: Y - X - Z. So if you imagine the object is aligned with the world axes ( no rotation at all ), you would first rotate around the local up axis, then around the local x axis and finally around the local z axis.


If you rotate around the world space axis ins$$anonymous$$d of the local axis you have to reverse the order. So you get the same result when you first rotate around the world Z axis, then around the world X axis and finally around the world Y axis.

avatar image
1

Answer by ImpOfThePerverse · Apr 22, 2018 at 03:46 PM

As for examples, one might be if you wanted to make something match the rotation that the player is facing without parenting the item. If it's a first person controller, the player will probably have one rotation about the Y axis that makes them look left or right, then a second child gameobject with a rotation about the X axis that makes them look up or down. Multiply the first quaternion by the second (order matters - the Y axis rotation should be first) and you get the overall rotation of the camera.

You could just get the rotation directly from the camera rotation, but say you had a more complicated controller where the X axis rotation happened about multiple nodes, like a neck node and an eye node, to make the viewpoint crane forward when you look down. If you wanted the final rotation of the eye node relative to the body, you'd multiply the neck node rotation by the eye node rotation.

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

Answer by Kudorado · Apr 22, 2018 at 11:56 AM

as @Firas4d answered, you can multipler two Quaternion by convert it into Vector3 by Quaternion.eulerAngles then multipler two Vector3 and convert it back to a Quaternion using Quaternion.Euler.

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

83 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

Related Questions

Make Quaternion affected by float 1 Answer

Vector3 and Quaternion issues. 2 Answers

Use Lerp to rotate object 2 Answers

rotation = Quaternion.identity doesn't change x rotation 1 Answer

How to rotate Quaternion around axis for a certain degree 2 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