Question by
tim-wheeler · Jul 07, 2016 at 11:21 AM ·
mathf.clamp
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);
}
}
Comment
Answer by goutham12 · Jul 08, 2016 at 07:28 AM
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);