1
votes

I'm a bit rusty of my trig, so I'm not sure the best way to do this ...

  • I need to position 2 movie clips on the stage that relate to each other
  • they can't be nested
  • the registation points are in the center

assume "clip B" is 50 px to the left of "Clip A" as pictured in the diagram to the left , when "clip A" is rotated, I need clip B to follow ( still 50px ) away but with new _x and _y relative to the rotation of "clip A" as in the diagram right

any help would be great

diagram

1

1 Answers

1
votes

Ok, I think your diagram is supposed to show A rotated in the second part right?

Basically you can consider the center of MovieClip B to be a point on a circle with the radius of 50 and with the angle based on A's angle. This code is for AS3 but I am guessing you are using AS2? All you need to do is add the underscore in front of x and y of the MovieClips. Also note this will rotate clockwise.

function rotateA(angleInDegrees:Number):void
{
    a.rotation = angleInDegrees;

    var bx:Number = Math.sin(angleInDegrees*(Math.PI/180))
    var by:Number = -Math.cos(angleInDegrees*(Math.PI/180))

    bx*=50;
    by*=50;

    bx+=a.x;
    by+=a.y;

    b.x = bx;
    b.y = by;
}