0
\$\begingroup\$

Lowering Unity App quality settings reduces mouse x turn speed, how to fix this?

I am not sure why this happens my only thought was time.timedelta is affected by the graphics quality setting in unity launcher.

when rotating a cube with input mouse x, the cube rotates at normal speed on high quality graphic settings, but lowering the graphic settings it begins to slow down. Inevitably at lowest it barely rotates.

using UnityEngine;

public class This : MonoBehaviour
{
    private float mouseTurn;
    private float turnSpeed = 64f;

    void Update()
    {
        mouseTurn = Input.GetAxis("Mouse X");
        transform.Rotate(0, mouseTurn * turnSpeed * Time.deltaTime, 0);
    }
}
\$\endgroup\$
  • \$\begingroup\$ Does that quality lowering include lowering the resolution? The timedelta certainly doesn't get affected \$\endgroup\$ – Bálint May 12 at 22:18
  • 1
    \$\begingroup\$ As always, you should show us your code here. There are ways to correct for variable framerate so that your motion speed is unaffected by the rendering performance, but there are also lots of ways to do that wrong. \$\endgroup\$ – DMGregory May 12 at 22:48
  • \$\begingroup\$ I am sorry I will now include my full code in the post., I have not changed resolution. \$\endgroup\$ – TeachMeEverything May 13 at 1:32
0
\$\begingroup\$

Input.GetAxis("MouseX") returns a value proportional to the distance the mouse has moved horizontally since the previous frame.

When your framerate is high, your mouse movement gets chopped into more, smaller pieces over the same time interval. When your framerat is low, a single long frame captures a wider span of mouse movement.

This would not be a problem ordinarily: if on each short frame you do a short camera movement, the total movement over the whole interval should match the total movement of the mouse.

The problem is this line:

transform.Rotate(0, mouseTurn * turnSpeed * Time.deltaTime, 0);

Here you're taking a mouseTurn variable, which as we saw before has a smaller value on short frames, and multiplying it by Time.deltaTime which also gets smaller on shorter frames.

The result is that you double-dip on time adjustment, multiplying your mouse speed by the square of the time interval. So short frames get an even shorter movement than they should, and long frames get an even longer movement than they should.

The solution: remove * Time.deltaTime when using a value like MouseX that has the time interval baked-in already, just like the mouse example shown in the Unity docs.

\$\endgroup\$
  • \$\begingroup\$ Awesome, Thank you, Did not know MouseX had time calculated in it. \$\endgroup\$ – TeachMeEverything May 13 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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