Skip to main content
Participant
April 30, 2009
Answered

Following an MC

  • April 30, 2009
  • 1 reply
  • 515 views
I am pretty new to actionscript, and am learning through experimenting with different game styles while reading online tutorials. However, I have been stumped. Here is my dilemma: My game is simple. You are a ball. the arrow keys move you smoothly around my box. if you touch a side, you come out on the other side, a perfect little square of infinity. I want smaller balls to chase after you while you move. I have found many a code to make a movie clip follow the mouse, yet none to make a movie clip follow another movie clip. I have tweaked certain codes for following the mouse to make them follow my movie clip, but that code goes on the first frame of the enemy_mc and it will only apply to one at a time? any help would be greatly appreciated.

note: (I'd rather not have the enemy slow down as it approaches the player, but if it's there then oh well)
This topic has been closed for replies.
Correct answer kglad

delete the trace() function.  i was using that to make sure the balls were assigned different speeds.

and i don't see an A-F anywhere in my code.

1 reply

kglad
Community Expert
Community Expert
April 30, 2009
var chaseBallA:Array = [ball1MC,ball2MC,ball3MC];

for(var i:Number=0;i .lt. chaseBallA.length;i++){
     chaseBallA.speed = 2+ i*Math.random();
}
chaseBallI = setInterval(chaseBallF,40);

function chaseBallF(){
     for(var i:Number=0;i .lt. chaseBallA.length;i++){
          var ang:Number = Math.atan2(chaseBallA._y-player._y,chaseBallA._x-player._x);
          trace(i+" "+chaseBallA.speed)
          chaseBallA._x += Math.cos(Math.PI+ang)*chaseBallA.speed;
          chaseBallA._y += Math.sin(Math.PI+ang)*chaseBallA.speed;
     }
     updateAfterEvent();
}

replace .lt. with <

Participant
April 30, 2009

my bad