x


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 );    
            }
more ▼

asked Apr 29 '12 at 12:39 AM

r6834 gravatar image

r6834
1 5 8 9

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 < minAngle)transform.rotation.x = minAngle;

Something along those lines?

May 04 '12 at 07:09 AM asafsitner

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.

May 05 '12 at 07:43 PM r6834

Did you try http://unity3d.com/support/documentation/ScriptReference/Mathf.Clamp for the parent's rotation already?

May 05 '12 at 07:47 PM Sebas
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1968
x727
x287
x181
x11

asked: Apr 29 '12 at 12:39 AM

Seen: 578 times

Last Updated: May 05 '12 at 09:49 PM