- Home /
Limit rotation from another script
I want to limit a rotation of of an object that is rotated by another script. I have a ray that hits an object, and allows it to rotate according to how much the finger is moved up and down. The child object is the object with the collider on it, and it rotates the parent object, so thats what I am trying to do here. I want to limit the amount the parent object can rotate on its local x axis to 45.
if (Input.GetTouch(i).phase == TouchPhase.Moved)
{
var touchDeltaPositionl:Vector2 = Input.GetTouch(i).deltaPosition;
hit.collider.gameObject.transform.parent.gameObject.transform.Rotate(Vector3.right * touchDeltaPositionl.y * -1 );
}
Why not just override the rotation when it get's out of the wanted range?
if(someTransform.rotation.x > maxAngle) transform.rotation.x = maxAngle;
if(someTransform.rotation.x < $$anonymous$$Angle)transform.rotation.x = $$anonymous$$Angle;
Something along those lines?
Thank you asafsitner, this is pretty much what I have done already, however the object does not stop rotating. I don't understand why either.
Did you try http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$athf.Clamp for the parent's rotation already?