X and Y inverted

Hey guys,

I’m wondering why X and Y are inverted on the fourth line. The code works, but shouldn’t it be X,Y and not Y,X ?

    x += Input.GetAxis("Mouse X") * 20;
            y += Input.GetAxis("Mouse Y") * 20;

            rotation = Quaternion.Euler(y , x , 0);

Basically, when I move my mouse on the Y axis, the Y rotation is moving.

When you move the mouse in the X axis, it’s moving horizontally (left/right). Presumably you want the object to rotate horizontally (left/right), too. What does that mean, to rotate horizontally? …It means to rotate about the Y (vertical) axis.

Similarly, when you move the mouse up and down, you probably want the object to rotate up and down to… which means a rotation about the X axis (assuming the camera is set up so that the X axis is horizontal and the Y axis is vertical).

All this depends on which way your camera is facing, of course.

1 Like