# How to rotate an object relative to another object's rotation

In my game, I have a movement system where the direction the WASD keys move the player is dependent on the camera. In other words, I have the W always move the player upwards, A always to the left, and so on, no matter where the camera is. This works great, but I need to find out how I can make the player face the direction they are moving.

``````transform.rotation = Quaternion.LookRotation(rotation);
``````

does not work because it just points the player directly along the X or Z coordinate, and not the actual direction of movement. If there is a way to rotate along the exact direction of movement, then that solves my problem. But if not, the way I figured I’d solve this was if I used a dummy object to always have the same y rotation as the camera, and rotate the player relative to that object. (the direction the object is facing is always 0, and the player rotates relative to that). I was just wondering if this was possible, OR if there was a way to rotate in the exact direction of movement.

Hi @Pigeon, when you want to apply one rotation to another rotation you can simply multiply the Quaternion representations of the rotations.

You can copy any object’s rotation to a new rotation in a Quaternion form (which is what Transform.rotation is):

``````   Quaternion q = object1.transform.rotation
``````

and use that to apply to any other objects current rotation

or you could just apply it directly:

``````    object2.transform.rotation = object2.transform.rotation * object1.transform.rotation
``````

but note in rotation, the order of operations is not commutative:

``````     A * B does not equal B * A
``````