Problem with Mouse Input

Hello!

I am facing a weird problem with my mouse input. I am currently improving my mouse look script, but it seems that my new computer mouse is not working correctly with the script. When I am starting a build version of the game, my Player keeps spinning around itself, even if I am not moving the mouse at all.

The problem only occurs when I am using the 3DConnexion CAD mouse. If I switch back to my old Logitech one, the game doesn’t have this behaviour at all and the script is working as intended. Is this a bug in Unity or am I doing something wrong script wise?

Here is the mouse look script (I am leaving out some parts which are not related to the mouse movement):

    public float LookSmoothDamp = 0.1f;
    public float LookClampBottom = 35f;
    public float LookClampTop = 55f;
    public float LookSensitivity = 5f;

    private float rotX = 0.0f;
    private float rotY = 0.0f;
    private float currentXRotation;
    private float currentYRotation;
    private float xRotationVelocity;
    private float yRotationVelocity;
    private float rotationY = 0.0f;
    private float rotationX = 0.0f;

    void Update()
    {
        // Get Inputs
        rotationX = Input.GetAxis("Mouse X");
        rotationY = -Input.GetAxis("Mouse Y");
    }

    void FixedUpdate()
    {
        switch (ControlMode)
        {
            case ControllerMode.FirstPersonFly:
                Rotate(rotationY, rotationX);
                break;
        }
    }

    private void Rotate(float x, float y)
    {
        rotY += rotationX * LookSensitivity;
        rotX += rotationY * LookSensitivity;

        //Weichen Übergang hinzufügen
        currentXRotation = Mathf.SmoothDamp(
                                                 currentXRotation, 
                                                 rotX, 
                                                 ref xRotationVelocity, 
                                                 LookSmoothDamp
                                        );

        currentYRotation = Mathf.SmoothDamp(
                                                 currentYRotation, 
                                                 rotY, 
                                                 ref yRotationVelocity, 
                                                 LookSmoothDamp
                                        );

        //Sichtradius in X einschränken
        rotX = Mathf.Clamp(rotX, -LookClampTop, LookClampBottom);

        var camTransform = currentCamera.GetComponentInChildren<Camera>().transform;
        currentCamera.transform.forward = new Vector3(
            camTransform.forward.x,
            0.0f,
            camTransform.forward.z
        );

        camTransform.rotation = Quaternion.Euler(
                                                 currentXRotation, 
                                                 currentYRotation, 
                                                 camTransform.rotation.z
                                        );

    }

All I can suggest is printing Input.GetAxis(“Mouse X”); with both mice and seeing if there is any input from your CAD mouse. Is so it might be a case of clamping small movements:

if(rotationX > 0.1 && rotationX < -0.1)

Thanks for the reply!

It seems that the mouse is working when I uninstall the mouse driver. With active mouse driver it will log the rotationX and Y values with -1, which should be the reason why my player is spinning.

Any suggestions on that? Or is it really a bug between Unity and the mouse driver?

Its does seem pretty damning to be your driver if uninstalling it fixes it :slight_smile: Certainly worth mentioning as a bug to Unity as well.

If your sold on this mouse you could get around this easily. Instead of using get axis you could recreate this functionality by reading Input.mousePosition and comparing the position to that the previous frame to get your difference and thus axis

Thanks for the answer, this might be a possible solution. Will take a look into that.

Nevertheless I will contact Unity directly in terms of the mouse driver. Maybe they find something.

1 Like

Ok, it seems there is no problem with Unity.
I tried to get the Input from the new CAD mouse in a complete new project. Just a little script which is logging the Input.GetAxis values. Everything works fine.

I think I found the real problem. In my Inputs I have two items named “Mouse X”. One is for the mouse input, the other one is for controller input. When I don’t connect my controller before I start the build, I will get the behaviour described in the first post of this thread. When I connect my XBOX 360 controller, BEFORE I start up the build, everything works fine.

It seems that my script, which is responsible for the controls, gets wrong values when I don’t have a controller attached. Any advice on this one?

Ahh that makes a lot of sense. Other than separating your controller input from mouse I am afraid not!

I see, thanks for the help!
Shouldn’t be to complex to seperate those.

1 Like