# How can I Multiply A Quaternion by a vector 3 without the order mattering

I have been stuck on this problem for over a month and I am desperate.

I am relatively new to unity so I may not explain it correctly but I will try my best. I am making a three player multiplayer game about one player controlling movement and the other two control the two hands. I use this code to try to rotate the hand using W and S for pitch, A and D for roll, Q and E for yaw control while also being rotated along with the camera.

``````public float x;
public float y;
public float z;
public GameObject camera;
public Quaternion rotation;

void Update ()
{
if (Input.GetKey(KeyCode.W)) x += 0.5f;
if (Input.GetKey(KeyCode.S)) x += -0.5f;
if (Input.GetKey(KeyCode.A)) z += 0.5f;
if (Input.GetKey(KeyCode.D)) z += -0.5f;
if (Input.GetKey(KeyCode.E)) y += -0.5f;
if (Input.GetKey(KeyCode.Q)) y += 0.5f;
rotation = camera.transform.rotation;
rotation *= Quaternion.Euler(0, 0, z);
rotation *= Quaternion.Euler(x, 0, 0);
rotation *= Quaternion.Euler(0, y, 0);
transform.rotation = rotation;
}
``````

I want to rotate the hand the same way no matter how it is already rotated. This already works with the rotation of y not affecting x or z or x not affecting z, but x does affect y. If you know how to do this it would be of incredible help.

Try this script. It will rotate `transform` in orientation of given `_cameraTransform`.

``````using UnityEngine;

public class HowcanIMultiplyAQuaternionbyavector3withouttheordermattering : MonoBehaviour
{

[SerializeField] Transform _cameraTransform;
[SerializeField] float _degreesPerSecond = 90;

void Update ()
{
float pitch = Input.GetAxis("Vertical");
float yaw = 0;
float roll = -Input.GetAxis("Horizontal");

if( Input.GetKey(KeyCode.E) ) yaw += -1;
if( Input.GetKey(KeyCode.Q) ) yaw += 1;

float stepThisFrame = _degreesPerSecond * Time.deltaTime;
Quaternion pitchRot = Quaternion.AngleAxis( pitch*stepThisFrame , _cameraTransform.right );
Quaternion yawRot = Quaternion.AngleAxis( yaw*stepThisFrame , _cameraTransform.up );
Quaternion rollRot = Quaternion.AngleAxis( roll*stepThisFrame , _cameraTransform.forward );
Quaternion rotationChange = pitchRot * yawRot * rollRot;
transform.rotation = rotationChange * transform.rotation;
}

#if UNITY_EDITOR
void OnDrawGizmosSelected ()
{
if( _cameraTransform!=null )
{
Vector3 position = transform.position;
Gizmos.color = Color.red;
Gizmos.DrawRay( position , _cameraTransform.right );
Gizmos.color = Color.green;
Gizmos.DrawRay( position , _cameraTransform.up );
Gizmos.color = Color.blue;
Gizmos.DrawRay( position , _cameraTransform.forward );
}
}
#endif

}
``````