Rotation functions on two axis

Hello,

I have a problem understanding the rotation functions.

I try to do a simple free camera controller (first person flying type), so I created a script and attached it to my main camera. The aim is to move forward/backwar/left/right with W/S/A/D and turn up and down with vertical mouse mouve and turn left and right with horizontal mouse mouve.
No problem with the translate part, but the rotation only works when I do only vertical rotation (around right axis) or horizontal rotation (around up axis). When I do both, I allways have a rotation on the forward axis, that I can’t explain.

I’m using the transform up and right vectors from my camera object, they’re supposed to be actualized, but I have the same result than when I use Vector3.up and Vector3.right wich are constants.

transform.Rotate(transform.up * Input.GetAxis(“Mouse X”) * horizontalMouseSensibility * Time.fixedDeltaTime)
transform.Rotate(transform.right * Input.GetAxis(“Mouse Y”) * verticalMouseSensibility * Time.fixedDeltaTime)

I tried lots of other things but always the same result :

transform.RotateAround(transform.position, transform.up, Input.GetAxis(“Mouse X”) * horizontalMouseSensibility * Time.fixedDeltaTime);
transform.RotateAround(transform.position, -transform.right, Input.GetAxis(“Mouse Y”) * verticalMouseSensibility * Time.fixedDeltaTime);

Even when forcing 0 to the rotation around Z axis, same result.

transform.rotation = new Quaternion(transform.rotation.x - Input.GetAxis(“Mouse Y”) * verticalMouseSensibility * Time.fixedDeltaTime, transform.rotation.y + Input.GetAxis(“Mouse X”) * horizontalMouseSensibility * Time.fixedDeltaTime, 0, transform.rotation.w);

Did I miss something ? :slight_smile: Thanks for tour help.

The easy way to deal with this is to nest your camera, so you have

[GameObject] - Rotate on Y axis
----[GameObject with Camera] - Rotate on X Axis

You rotate one on the Y-axis and the other on the X-axis.

Thank you for the answer, I did that for a first person standard controller and it worked well, but I would like to understand the logic of the rotate function.
When I do rotations on the local up and right axis of my object, the Z transform.rotation of my object should always stay at 0.