Zeke-27
September 9, 2019, 5:12am
1
I’ve got a simple script for rotating a character with MouseDrag but I’m not sure how to apply limits to their rotation. I know how to clamp movement but rotation seems to be a little more complicated. Anyone know how to do this?
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);
}
Laiken
September 9, 2019, 5:40pm
2
Is this what you are looking for?
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);
Vector3 myRotation = transform.rotation.eulerAngles;
myRotation.x = Mathf.Clamp(myRotation.x, minValue, maxValue);
myRotation.y = Mathf.Clamp(myRotation.y, minValue2, maxValue2);
transform.rotation = Quaternion.Euler(myRotation);
}