c# – How Can I smooth out the Values of Mouse X in Unity

I am trying to create a script that tilts the cam on the Z axis dynamic so that when you look to the right the camera tilts sideways like it is getting pulled but somehow my cam just jitters and I know why but I dont’t know how to fix hit. The Reason is the value of the Mouse X axis. When I am printing it out I can see that ervy second value of it is 0 and the other ones are the real value so my camera snaps from 0 to the rotion I want.

The first part in the lateUbdate Function is just for the First person controll of the cam

    public float MausEmpfindlichkeit;
    float CamTilt;

    //transform
    public Transform PlayerBody;


    //floats
    float Xrot = 0f;


    //Scripte
    public RotaionSpeed PlayerSpeed;

    // Start is called before the first frame update
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

    // Update is called once per frame
    void LateUpdate()
    {
        TurnCamToSpeed();

        float MausX = Input.GetAxis("Mouse X") * Time.deltaTime * MausEmpfindlichkeit;
        float MausY = Input.GetAxis("Mouse Y") * Time.deltaTime * MausEmpfindlichkeit;

        Xrot -= MausY;

        transform.localRotation = Quaternion.Euler(Xrot, 0f, CamTilt);
        PlayerBody.Rotate(Vector3.up * MausX);

        print(Input.GetAxis("Mouse X"));

    }

    void TurnCamToSpeed()
    {
        float CamTiltValaue = Random.Range(0, Input.GetAxis("Mouse X"));
        CamTilt = -CamTiltValaue * 3;
        
    }

My question is, how do I prevent that from happening and have a smooth Value of The Mouse X axis

This is the current behaviour but it is hard so because of the low fps rate of the gif

Read more here: Source link