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.