Rotation problems in x, y axes after rotating in z-axis

Hey folks,

In my project I’m basically using the standard MouseOrbit.js script to rotate the camera around an object.

I’ve added additional functionality that allows me to rotate the camera around the z-axis which initially seemed to work fine, but after playing with it for a while I’ve found that the x and y rotation is off after I’ve rotated in the z.

So, if I rotate the camera 90 degrees in the z-axis, then drag the mouse along the x-axis, I seem to be rotating the camera in the y-axis instead of the x-axis.

Does that description make any sense? Basically, these rotation is calculated like so:

x += Input.GetAxis(“Mouse X”) * xSpeed * 0.02;
y -= Input.GetAxis(“Mouse Y”) * ySpeed * 0.02;

var rotation = Quaternion.Euler(y, x, myZ);

transform.rotation = rotation;

Somehow I need to change how I calculate the x and y rotation when myZ is changed (i.e. when I rotate 90 degrees it looks like I’ll want the axes flopped).

I’m having some difficulty with the math involved, so I figured I’d check to see if anyone had run across this problem before.

Thanks,
Jared

Maybe try

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

Thanks for the help. I tried your suggestion and it seemed to help the problem with the x and y rotation, but created a new problem where the z rotation no longer works as desired.

The z rotation should take into account the x and y rotation. Using your suggestion the z rotation seems to be independent of the x and y rotation… if that makes any sense.

If not I’ll try to post a better explanation later.

Thanks again,
Jared