Rotation is faster in build

I have this code for rotating the player and camera and when I build the game the rotation is faster.

I guess that’s because of the Time.deltatime but when I don’t multiply the values with the deltatime I get a slower rotation with the controller in the build (although the _rotationVelocity value is the same in the build and the editor)

Here is the code:

    private void HandleRotation()
    {
        float scalingFactor = Time.deltaTime;
        Vector2 mouseDelta = inputManager.inputActions.Player.CameraRotation.ReadValue<Vector2>();

        _cinemachineTargetPitch += -mouseDelta.y * cameraSensitivity * scalingFactor;
        _rotationVelocity = mouseDelta.x * cameraSensitivity * scalingFactor;

        // clamp our pitch rotation
        _cinemachineTargetPitch = ClampAngle(_cinemachineTargetPitch, -maxXRotation, maxXRotation);

        // Update Cinemachine camera target pitch
        cameraTransform.localRotation = Quaternion.Euler(_cinemachineTargetPitch, 0f, 0f);

        // rotate the player left and right
        playerTransform.Rotate(Vector3.up * _rotationVelocity);
    }

The mouse delta shouldn’t be scaled by Time.deltaTime. So instead you’ll need to have two input values and only scale the controller input value by Time.deltaTime.

2 Likes

Why the mouse input shouldn’t be scaled and the controller input should?

The mouse delta is already frame rate independent. Whereas the controller input is in the range of -1 to +1 and so it needs to be scaled to keep the movement rate constant across different frame rates.

2 Likes

Thanks for the explanation, I appreciate it!