hi.
I have a code like this that rotates the camera:
if (Input.GetMouseButtonDown(0))
{
prevMousePos = cam.ScreenToViewportPoint(Input.mousePosition);
}
if (Input.GetMouseButton(0) )
{
Vector3 direction = prevMousePos - cam.ScreenToViewportPoint(Input.mousePosition);
camRotate.transform.Rotate(new Vector3(1, 0, 0), direction.y * 180);
camRotate.transform.Rotate(new Vector3(0, 1, 0), -direction.x * 180, Space.World);
prevMousePos = cam.ScreenToViewportPoint(Input.mousePosition);
}
and it works great, but how do I constrain the x-axis rotation? if I try to take a rotation like this
this.transform.rotation.eulerAngles.x
then the return value does not match the one in the inspector (matches only from 0 to 90 degrees, and after 90 it starts to go down again and it turns out that this function returns 50 if both 50 and 120 degrees are in the inspector). I want to make it impossible to make a full turn