Mouse Rotation + Screen Resolution

Hi!

I am facing a weird problem. I have a Mouse Look script for a First Person view. When I am working in the Editor everything is working as expected. But when I build everything to a Windows Player and change the resolution, the mouse rotation is slower and more laggy. First I thaught there is a problem with Time.deltaTime, but it seems I made another mistake.

As I am working on a Viewer software, which will be run in Window Mode and where the User can change the resolution on runtime, this is quiet annoying. Here is the code for the Mouse Look (part from a bigger script):

    private float rotX = 0.0f;
    private float rotY = 0.0f;
    private float rotZ = 0.0f;

    void Update() {
        rotationX = Input.GetAxisRaw("Mouse X") * Time.deltaTime;
        rotationY = -Input.GetAxisRaw("Mouse Y") * Time.deltaTime;
    }
   
    void FixedUpdate() {
     Rotate(rotationY, rotationX, 0.0f, false);
    }

    private void Rotate(float x, float y, float z, bool firstPerson)
    {
        rotX += x * mouseSpeed;
        rotY += y * mouseSpeed;
        rotZ += z * mouseSpeed;

        if (firstPerson)
        {
            rb.transform.Rotate(rotX, rotY, rotZ);
        }
        else
        {
            var camTransform = currentCamera.GetComponentInChildren<Camera>().transform;
            currentCamera.transform.forward = new Vector3(
                camTransform.forward.x,
                0.0f,
                camTransform.forward.z
            );

            camTransform.Rotate(rotX, rotY, rotZ);
        }
    }

use the screen resolution in your update.

Input.GetAxisRaw("Mouse X") / Screen.Width * Time.deltaTime * 100;

This converts the axis to a percentage of the screen rather than pixels.

Thanks for this information.

This makes the movement smoother on different resolutions (because I use a resizable player window), but I am now facing another problem. When I use the mouse, the camera begins to spin until I move the mouse back to the “zero point”. Its like I am using the mouse like a stick on a controller. Once I put the stick in one direction the camera spins, until I push the stick back in the other direction.

What I want to do is to move the mouse and when I stop it, the camera rotation should also stop.
I guess the problem is somewhere here:

rotX += x * mouseSpeed;
rotY += y * mouseSpeed;
rotZ += z * mouseSpeed;

because I am adding the value to my rotation values. Any ideas?

so, the line after that, should be…

mouseSpeed = 0;

This eliminates every movement speed. The variable mouseSpeed controls the sensitivity. If I set it to zero, my character won’t rotate anymore.