- Home
- Tutorials
- Flash
- Intermediate
- Balls chain with constraints, colision, mouse follow and the math needed
Balls chain with constraints, colision, mouse follow and the math needed

Simple: how to make a movie to follow another movie
function follow(mc, myTarget, lowerDistance) {
orig = {x:mc._x, y:mc._y};
dest = {x:myTarget._x, y:myTarget._y};
myAngle = Math.atan2((orig.y-dest.y), (orig.x-dest.x));
myDistance = Math2.distanceBetween(orig.x, orig.y, dest.x, dest.y)-lowerDistance;
if (myDistance+lowerDistance>=lowerDistance) {
mc._x -= Math2.cos(myAngle)*(myDistance/reductionMultiplier);
mc._y -= Math2.sin(myAngle)*(myDistance/reductionMultiplier);
}
}
Now we have another argument (the target movie) instead of using the mouse position. That's all!
Next section will cover how to keep a distance between balls

