FPS Dependant movement

Every since I upgraded my project from 2018.4.10f1 to 2021.1.0f1 I’ve noticed a huge increase in my FPS inside the editor. It goes up to 300 when I look at an empty scene but drops dramatically to 30~ when I look at a lot of objects.

Now this by itself is not a problem as my scene is not optimized in the least.
However, it causes my movement and update based functions to slow down or speed up.
I am using Time.deltaTime to scale every change and this seems to cause to opposite reaction from my frame rate.

For example, camera rotation speeds up when fps is low and slows down to a crawl when it’s high.
This make sense because higher frame rate means less delta between frames but I never had this problem. As far as I know multiplying by the deltaTIme should remove all inconsistencies and make it run smooth no matter the FPS.

I also player with the vSync options in quality to try and reduce or clamp the FPS but nothing affected it

Are you incorrectly lerping using delta time as the T parameter?

1 Like

We can’t tell you what’s wrong with your code if we can’t see your code.

This is the code snippet in charge of camera movement
Would appreciate if someone can point to what might be the cause

void LateUpdate()

void LateUpdate()
    {
        float mouseX = Input.GetAxis("Mouse X") * sensitivity.x * Time.deltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * sensitivity.y * Time.deltaTime;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
       
        switch(_lookState)
        {
            case LookState.TURN_BODY:
            playerBody.Rotate(Vector3.up * mouseX);
            break;

            case LookState.TURN_HEAD:
            break;
        }
    }

Multiplying mouse axis input by Time.deltaTime is unecessary and will introduce framerate-dependent jitter into your game. Mouse axis data is already framerate independent.

3 Likes

Thanks PraetorBlue, that was it!
I never knew that this function was not frame dependant…

Just be careful. Most axes like the built in “Horizontal” and “Vertical” axes behave in a way that they will be framerate dependent if you blindly apply their result to some kind of motion in game.

It’s not the function itself but that particular axis (“Mouse X” and “Mouse Y” which is framerate independent.

The way I think about this aspect of user inputs like this is: If I as a player should be able to achieve something by “holding” the input at a particular state, then the input must be multiplied by Time.deltaTime to achieve correct behavior with different framerates.

ex: Holding “up” key => Character continually runs forward => needs deltaTime
Holding the joystick in the “right” position => camera continually rotates to the right => needs deltaTime
But holding the mouse to the right of where it was => the camera stops rotating as soon as you stop moving the mouse => NO deltaTime

THANK YOU SO MUCH THIS THREAD IS GONNA HELP ME SO MUCH

2 Likes