Stop camera from stuttering when looking straight up or down

Hey, I’m using the new input system and I’m trying to get the right stick to control where the camera is looking, my games controls should allow the players camera to rotate freely in any direction (except z) including going upside down, but my code isn’t working.

Whenever the x rotation of the camera tries to go above the X rotation 90 or below the X rotation -90, the camera rotation tries not to pass that 90 mark and resets itself to 90, and if it could do this without stuttering I would call it good and move on, but the effect it has now is unacceptable.

Here’s what I wrote:

    void Update()
    {
        currentRotation = transform.localEulerAngles;
        Vector2 rotationInput = ungodlyControlsInputAsset.PlayerControls.RotateCamera.ReadValue<Vector2>();
        Debug.Log(rotationInput);

            float h = gamepadHorizontalSpeed * rotationInput.x;
            float v = gamepadVerticalSpeed * -rotationInput.y;

            currentRotation += new Vector3(v, h, 0f);
            transform.localEulerAngles = currentRotation; 

    }

I hope you can help!

I checked your @ChaosRobin code in Unity. Everything worked fine. The only thing I doubted was your input, so I changed it to the old input for myself.

public class CameraTest: MonoBehaviour
{
    public float gamepadHorizontalSpeed;
    public float gamepadVerticalSpeed;

    Vector3 currentRotation = Vector3.zero;
    Vector2 rotationInput = Vector3.zero;

    void Update()
    {
        currentRotation = transform.localEulerAngles;
        rotationInput.x = Input.GetAxis("Mouse X");
        rotationInput.y = -Input.GetAxis("Mouse Y");

        Debug.Log(rotationInput);

        float h = gamepadHorizontalSpeed * rotationInput.x;
        float v = gamepadVerticalSpeed * -rotationInput.y;

        currentRotation += new Vector3(v, h, 0f);
        transform.localEulerAngles = currentRotation;
    }
}

Check your Debog.log() in the console panel and also any error that may cause this malfunction.