6 Replies Latest reply on Apr 30, 2009 11:47 AM by kglad

    Following an MC

    JackColby333
      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)
        • 1. Re: Following an MC
          kglad Adobe Community Professional & MVP
          var chaseBallA:Array = [ball1MC,ball2MC,ball3MC];
          
          for(var i:Number=0;i .lt. chaseBallA.length;i++){
               chaseBallA[i].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[i]._y-player._y,chaseBallA[i]._x-player._x);
                    trace(i+" "+chaseBallA[i].speed)
                    chaseBallA[i]._x += Math.cos(Math.PI+ang)*chaseBallA[i].speed;
                    chaseBallA[i]._y += Math.sin(Math.PI+ang)*chaseBallA[i].speed;
               }
               updateAfterEvent();
          }
          
          

           

           

          replace .lt. with <

          1 person found this helpful
          • 2. double post
            JackColby333 Level 1

            my bad

            • 3. Re: Following an MC
              JackColby333 Level 1

              Okay edit I am figuring it out. I put the code on the enemies layer, and used the instance names ball1MC and so on. What does the A-F mean and what does the

               

              2.48724414547905
              2 2.62374331708997
              0 2
              1 2.48724414547905
              2 2.62374331708997

               

              mean in my output box?

              • 4. Re: Following an MC
                kglad Adobe Community Professional & MVP

                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.

                • 5. Re: Following an MC
                  JackColby333 Level 1

                  Okay. done. I think i figured it out once i actually started looking at the code. Like I said I'm really new to a lot of the different concepts of Action script. And I figured it out your right there is no A-F i was just realizing what they were and what not. Thank you so much I have been looking for days for a code.

                  • 6. Re: Following an MC
                    kglad Adobe Community Professional & MVP

                    you're welcome.