3 Replies Latest reply on May 11, 2009 12:24 PM by kglad

    Agro range on following code

    JackColby333

      A couple weeks ago, I was assissted by kglad in recieving a code that makes enemy MC's follow a player mc controlled with the arrow keys, and food MC that moves away from the player. the code for the food is as follows:

       

      var runBallA:Array = [food1MC,food2MC,food3MC];

      for(var i:Number=0;i < runBallA.length;i++){
           runBallA[i].speed = -3;
      }
      runBallI = setInterval(runBallF,40);

      function runBallF(){
           for(var i:Number=0;i < runBallA.length;i++){
                var ang:Number = Math.atan2(runBallA[i]._y-player._y,runBallA[i]._x-player._x);
                runBallA[i]._x += Math.cos(Math.PI+ang)*runBallA[i].speed;
                runBallA[i]._y += Math.sin(Math.PI+ang)*runBallA[i].speed;
           }
           updateAfterEvent();
      }

       

       

      my question is how do i put an agro range on this code so that the foodMC moves away from the player only when the player is within (i.e.) 100 pixels?