# Need Help with Mathf.Clamp

PROBLEM:
This code rotates the attached obj that has it, via Mouse Y and Mouse X. The problem is I need the rotation on both axes to not exceed lets say 70 degrees && -70 degrees. Please tell me what I should put into this code to make this work. I can not get it figured out.

CODE:-----------------------------------------------

[SerializeField]
float rotateSpeed = 70f;

private void Update()
{
//Get X and Y Rotation values in respect to rotateSpeed, idk why Deg2Rad
float rotY = Input.GetAxis(“Mouse Y”) * rotateSpeed * Mathf.Deg2Rad;
float rotX = Input.GetAxis(“Mouse X”) * rotateSpeed * Mathf.Deg2Rad;

//SideNote: Y rotation on Self & X rotation on World, prevent Z from rotating with them. We //also sub1 from rotY to fix inversion.

//Description: Rotating attached obj accordingly.
//TODO: I need these transforms to not exceed -70 & 70 degrees.
transform.Rotate(Vector3.right, rotY * -1, Space.Self);
transform.Rotate(Vector3.up, rotX, Space.World);

}

Hi,
One way is to use a separate Vector3 for calculating your angles.
Apply Mathf.Clamp to those values before assigning them back to the transform.