9 Replies Latest reply on Jun 8, 2006 11:03 AM by kglad

# Keeping an object level to the floor at the end of a chain

I have a chain of two lines. One rotates from a fixed point on the floor, the second rotates from a fixed point and the end of the first. At the end of the second line I have an object I'd like to swing freely. I'd always like it to stay 'level' to the floor, regardless of the position of the two lines. So, sort of link robotic arm dangling something.

Is there a way to 'get' the angle of an object?

Thank you....
• ###### 1. Re: Keeping an object level to the floor at the end of a chain
Not sure I understand the problem... Is the object moved by script? In that case you could change only the _x property, not _y. But I guess there's more to it... what do you mean by 'angle'? You could get the angle between line 2 and the object with some basic trigonometry, but again, I'm not sure what your goal is. Maybe you can explain it more detailed?

greets,
blemmo
• ###### 2. Re: Keeping an object level to the floor at the end of a chain
Alrighty: I'm simulating the motion of an excavator. During it's motion, it has 3 primary components. The 'boom', the 'stick' and the 'bucket' I'm going to be as detailed as possible about my build.

Visit: http://net.shoring.com/movax_test.html

It'll ask for a u/n and p/w. Use 'guest' for both fields.

The movement is simply done by using the arrow keys to control the playhead inside the yellow and black line. I used a motion tween to restrict the range of movement.

The blue box, is what I'd like to keep 'level' in relationship to the thick black line.

Hope that helps...sometimes a visual reference makes all the difference.

Thanks for the attention....
• ###### 3. Re: Keeping an object level to the floor at the end of a chain
the bucket will always remain in a vertical (or horizontal depending upon how you look at it) position. the angle between the boom and stick will be 90 degrees minus the angle between the boom and horizontal.
• ###### 4. Re: Keeping an object level to the floor at the end of a chain
That makes total sense, however since the momevent of the boom and the stick are controlled motion tweens - I can do this if I new how to read the angle of those items ? I know you can get x/y numbers, but can you get an angle of and object? Is that possible?

thanks....
• ###### 5. Re: Keeping an object level to the floor at the end of a chain
do you mean:

myMovieClip._rotation??
• ###### 6. Re: Keeping an object level to the floor at the end of a chain
I have tried that - it can only work if I know how much to rotate it by. As you can see with the animation: the angle varies depending on the postion of the other elements. I could use that if I knew the angle of the yellow line (stick) at every moment. Then with some simple math it could work.

So, the problem is that the amount it has to rotate changes all the time..... so it sort of has to dynamically adjust constantly.....

quite the challenge?
• ###### 7. Re: Keeping an object level to the floor at the end of a chain
yes, you can get the angle of an object. if you want to know the angle of the line connecting x1,y1 and x2,y2 you can use:

Math.atan2(y1-y2,x1-x2); // this is in radians. multiply by 180/Math.PI for degrees
• ###### 8. Re: Keeping an object level to the floor at the end of a chain
So, x1 and y1, etc: I have to input those numbers manually? OR can I put a series of blank MC's has hinge points to pull X/Y numbers from?

so it would looke like: Math.atan2(hinge1_y-hinge2_y, hinge1_x-hinge2_x);

I suppose right now I'm really wishing I paid more attention in geometry - which I took something like 14 years ago...

thanks

• ###### 9. Re: Keeping an object level to the floor at the end of a chain
you don't need to enter anything manually and you don't need work-around movieclips at hinge points. i'm not sure how your project is set-up but normally you would have the user control the rotation of the boom (with registration point at its left), the length of the boom and the length of the stick. everything else is calculable (by flash) from there.

for example, you might want to know where to move the stick so it stays at the end of the boom when a user rotates or extends the boom. the sticks _x and _y properties are given by: