A Flash Developer Resource Site

Thread: chain effect connecting 2 mcs? Help.

1. chain effect connecting 2 mcs? Help.

Hey guys/gals never posted here, i was wondering if you could help me out.

My problem is that i have a mc called screen which is a large computer screen. And i have 3 pipes which i want to make a chane type effect between a ground mc and the screen mc. But i dont know the math. The screen sort of floats around and i want the screen mc to be connected using these pipes to the ground mc and rotate and place the pole mcs accordinly. It's sort of hard to describe so i made a pic of what im getting at. Hopefully some one knows how its done. Ive seen it before.

2. i've tried this before but wasn't able to do it but it should be quite simple. do a search on chaos theory and the double or dual pendulum

i'll give it a try and post it for you if i get it

3. Thanks a_slosh ill give it a search. But it would be much appretiated if you could post it if you work it out. I will do the same if i work it out first. Thanks

4. In you illustration, how is movement imparted? Can you drag the big square?

Is this supposed to behave like a desk lamp? Which points are fixed?

One way to model this is as masses connected by springs - but in this case you would use a very stiff spring with a lot of damping, so that the length stays more or less constant.

Try setting gravity to 0
air resistance to .49
and stiffness to .4

Be careful to raise resistance first

The problem with that model is that it is still a little too springy. If you add even more damping, you can get rid of more of the springiness. The advantage of the model is that it relatively simple, mathematically.

What you probably *really* want is something called inverse kinematics, but this requires more mathematical sophistication than the spring model.

- Jim

5. The only problem i see me facing using this model is that i am using premade connecting pole images which i dont want to resize at all. And the yes it behave's like a lamp the fixed points are to the base and the lamp head. I just cant see how i will achieve this properly.

PS. Nice useful site by the way.

6. If you use spring-physics method to provide you with the endpoints of each segment, then once you know the endpoints, you can position each segment to match. The endpoints would be where the masses (the dots) are in the spring model.

Let's say you have calculated that a particular segment has endpoints x1,y1 and x2,y2.

You set up the movieclip so that it's registration point (it's pivot point) corresponds to x1,y1.

code:
```
segment._x = x1;
segment._y = x2;
```

Then you rotate it into place, by computing the angle between the two endpoints. This code assumes that each segment lies flag, pointing to the right when it is drawn without rotation (0 degrees).

code:
```
var angle = Math.atan2(y2-y1,x2-x1);
segment._rotation = angle * 180/Math.PI;
```

As long as you minimize the springiness of the model, and you assign 'resting' lengths that correspond to the length of your movieclip segments, it should be close enough.

* * *

Finally, if you want to do it in a more rigorous way, here are some articles on inverse kinematics - a technique often used to animate articulated models.

http://freespace.virgin.net/hugo.elias/models/m_ik.htm

http://www.euclideanspace.com/physic...matics/joints/

Hope this helps...

- Jim

7. After writing my last post, I decided to try it out. I was able to cobble this together in about an hour using my SpringSim class.

Here is the demo - it shows the virtues and the flaws of this model. You can reposition the lamp by moving the joints. More on the flaws below.

Desk Lamp Demo

And here is the source code.

Desk Lamp Source Code (zip)

The source code I added reads as follows (most of the hard work occurs inside the spring phsyics library).

code:
```
// Desk lamp simulation using spring phsyics
// -- Jim Bumgardner, 2004

#include "SpringSim.as"

// Setup the spring simulatoin
//                   gravity, stiffness, friction
ss = new SpringSim(this, 0.0,  0.5, 0.99);

// define the connections between the joints

// Anchor the base and disallow it to be pulled off
joint1.setDotProps(true, false);
delete joint1.onPress;

// Set up each joint to point in the right direction.
for (var i = 1; i <= 3; ++i)
{
this['joint'+i].onEnterFrame= function()
{
var a = Math.atan2(this.pointAt._y - this._y, this.pointAt._x - this._x);
this._rotation = a*180/Math.PI;
}
}

```

As you maniuplate the lamp, you'll notice that the joints tend to pull apart. This is because I'm using a very simple dragging function that places no restrictions on where you can drag things, and allows you to drag to illegal positions, where the length of the joints is exceeded.

Like I said earlier, this isn't as good as inverse kinematics, but it's easier...

8. Wow thats exactly what i want . You dont happen to have it in mx format though do you. Had a look at your SpringSim.as and it pure genious. How long have you been working on that ? Thanks alot for your help.

9. I worked on the SpringSim class for a couple of weeks about six months ago. My original intent was to add some additional stuff to it so it could be used for creating armatures for character animation.

One day...

Here's an MX version of the .fla file.

If you take a look at the invididual movieclips for the joints, you'll see that they are all FLAT - the pivot point on the left and the connecting point on the right . This corresponds to 'zero degrees' rotation.

- Jim

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap