- Home /
Set max allowed angle?
I rotate an object around another object by using RotateAround and the Mouse Y Axis. Now I would like to set max angles, so, the transform can not have an angle bigger than 60 and smaller than -60. Is that possible?
var Speed : float = 10; var Achse : Transform;
function Update () { var rotationY : float;
rotationY += Input.GetAxis("Mouse Y") * Speed;
rotationY = Mathf.Clamp (rotationY, -60, 60);
transform.RotateAround(Achse.position,Achse.right,-rotationY);
}
Answer by poncho · Apr 21, 2011 at 01:53 PM
before the transform.RotateAround you can check the transorm new angle
would be like this
float newAngle = transform.eulerAngles.y+rotationY;
if(newAngle<=60 && newAngle >= -60)
{
transform.RotateAround(Achse.position,Achse.right,-rotationY);
}
hope this helps
It works just for the positive angle because Unity handles the -60 as 300.
=P well you can change the statement to newAngle=300 and that should be it
Your answer

Follow this Question
Related Questions
Limit Y Axis transform.RotateAround 1 Answer
How can I limit my rotation around an object ? 1 Answer
Transform.RotateAround(Vector3 axis, float angle) - what happens with only two arguments? 3 Answers
Limit rotation when using RotateAround() 1 Answer
How do I limit the x axis on a first person controller? 1 Answer