Home Game Development unity – Mathf.Clamp not Working Properly

unity – Mathf.Clamp not Working Properly

0
unity – Mathf.Clamp not Working Properly

[ad_1]

I wish to clamp the vertical rotation of the primary individual controller I used to be making. I wish to prohibit the vertical rotation of the principle digital camera between -90 and 90 levels. The code is as follows:

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;

public class MouseY : MonoBehaviour
{
    [SerializeField]
    non-public float _sensitivity = 5.0f;
    non-public float _verticalInput;

    // Update is named as soon as per body
    void Update()
    {
        _verticalInput = Input.GetAxis("Mouse Y") * _sensitivity;
        Vector3 lookDirectionY = rework.localEulerAngles;
        lookDirectionY.x -= _verticalInput;
        lookDirectionY.x = Mathf.Clamp(lookDirectionY.x, -90f, 90f);
        rework.localEulerAngles = lookDirectionY;
    }
}

In the above code, Mathf.Clamp doesn’t work for -90. On reaching 0 levels, it reels again to the +90 levels. What might be the rationale for this and the best way to resolve it?

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here