How do I clamp the y rotation of roty

Sorry guys I know this has been answered in many different ways but I just cant work out how to apply to my code. could you help me to limit the roty so it only rotates about 10 degrees. Many thanks Tim

public class rotteeth : MonoBehaviour
{
float RotSpeed = 5;

void OnMouseDrag () 
{
	float rotx = Input.GetAxis("Mouse X")*RotSpeed*Mathf.Deg2Rad; 
	float roty = Input.GetAxis ("Mouse Y")*RotSpeed*Mathf.Deg2Rad;

	transform.RotateAround(Vector3.up, -rotx);
	transform.RotateAround (Vector3.right, roty);
}

}

1 Answer

1

transform.RotateAround(Vector3.up,mathf.clamp(min value,max value, -rotx));
initialize that min and max values according to your requirment…

The code has to be tested.if it won’t work then use transform.eularangles to change the angle.

i mean
transform.eularangles = new vector3(xtorotate,mathf.clamp(min value,max value, -rotx),z to rotate);