[Math] Why is this possible ?

Hello guys,

I am trying to do a Movement Controller which moves to player forward relative to its direction. When I have done some research on this topic, I noticed that this line of code would do the trick:

Vector3 direction = transform.rotation * new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));

Why are we able to apply the rotation (Quaternion as datatype) to the Vector3 which stores the Input values.

The next thing I noticed: If we turn around the statement, so the Vector3 is instaniated first, the line of code will no longer work and throw and error.

you are unknowingly using the Quaternion.operator* :

As you can see you can use the operator for

  1. Quaternion*Quaternion (returns Quaternion)

  2. Quaternion*Vector3 (returns Vector3 —> Your case)

Everything else, like Vector3*Quaternion will throw an error