Sunday, May 1, 2016

Lowering Unity launcher graphic quality settings reduces mouse x turn speed, does quality affect time?


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);
}
}

Answer



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.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...