-1
\$\begingroup\$

I got a small script from the official Unity forum which is:

public class MouseRotationUpDown : MonoBehaviour {
    public float RotationSpeed = 5;

    void Update () 
    {
        transform.Rotate(Input.GetAxis("Mouse Y") * RotationSpeed,0, 0 /** Time.deltaTime*/, Space.World);
    }
}

This script should rotate (as in looking up and down) the camera, based on my mouse movement. But instead of just rotating the camera over the X axis (up & down) it rotates the camera over all three axis at once.

This is the only script attached right now.

\$\endgroup\$
  • \$\begingroup\$ You're rotating with respect to Space.World. So if your camera's z-axis is pointing along the world x-axis, then what you're applying as a pitch (world x-axist rotation) will be observed as a roll (local z-axis rotation). Does the problem persist if you try Space.Self, or play with different starting orientations for the camera? \$\endgroup\$ – DMGregory Jun 22 '15 at 19:55
  • \$\begingroup\$ @DMGregory You fixed the issue. I think I should've gone more in depth when reading up on rotation. Didn't know the details about the 4th parameter in the function. \$\endgroup\$ – Giani Noyez Jun 22 '15 at 19:59
1
\$\begingroup\$

DMGregory posted this and I'm just copying his comment to be able to close this question with an answer.

You're rotating with respect to Space.World. So if your camera's z-axis is pointing along the world x-axis, then what you're applying as a pitch (world x-axist rotation) will be observed as a roll (local z-axis rotation). Does the problem persist if you try Space.Self, or play with different starting orientations for the camera? – DMGregory

So I changed Space.World to Space.Self and the issue got fixed. Thanks everyone for leading to this answer.

\$\endgroup\$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.