#Weird camera stuttering

1 messages · Page 1 of 1 (latest)

river quiver
#

I'm trying to make first person movement with the new Input System and I'm noticing weird stuttering while moving the camera, it's a lot more noticable on lower sensitivities and pretty annoying. How can I fix this?

using UnityEngine;

public class MouseLook : MonoBehaviour {
    public Transform playerBody;
    [Range(1f, 100f)]
    public float mouseSensitivity = 10f;

    private InputMaster controls;
    private Vector2 mouseLook;
    private float xRotation;

    private void Awake() {
        controls = new InputMaster();
        Cursor.lockState = CursorLockMode.Locked;
    }

    private void Update() {
        Look();
    }

    private void Look() {
        mouseLook = controls.Player.Look.ReadValue<Vector2>();

        var mouseX = mouseLook.x * mouseSensitivity * Time.deltaTime;
        var mouseY = mouseLook.y * mouseSensitivity * Time.deltaTime;

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

        transform.localRotation = Quaternion.Euler(xRotation, 0, 0);
        playerBody.Rotate(Vector3.up * mouseX);
    }

    private void OnEnable() {
        controls.Enable();
    }

    private void OnDisable() {
        controls.Disable();
    }
}
#

For some context, InputMaster is a script for my input actions (see screenshot for bindings)

leaden cedar
#

Don't multiply mouse input by deltatime

river quiver
#

Why not?

leaden cedar
#

Mouse input is already in distance per frame units. Multiplying by deltatime again isn't needed