# 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 ,

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.

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.

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`.