Used this code found here CBA
float h = horizontalSpeed * Input.GetAxis("Mouse X");
float v = -verticalSpeed * Input.GetAxis("Mouse Y");
transform.Rotate(v, h, 0f);
It works. But if I move the cursor in circles the camera slowly rotates around it’s local z-axis tilting the world view. The camera is otherwise stationary.
Does anyone know what to do to rectify this? All help is appreciated.
use
transform.Rotate(v, h, transform.rotation.z);
OR
transform.rotation += Quaternion.Euler(v, h, 0f);
instead. You are changing current rotation along z axis to 0f, which is not correct.
Well looks like I finally found the answer. The problem is gimbal lock apparently. All though I thought one of the advantages of using quaternions was to avoid gimabl locks.
If anybody else has this problem use the code posted on the following link. It worked for me. He also explains the problem.
Sidenote: Find it weird that gimabl lock is not mentioned in the official documentation for Input.GetAxis(see link at top of post). My code was taken directly from there and didn’t work. If we can’t rely on the creators of the game engine who can we rely on?