1 Reply Latest reply on May 11, 2006 3:27 AM by blemmo

    bounce

    Abyu
      hi
      please say the actionscrit required for a movie clip to bounce away when it hits anyother movie clip
      so that after it hits it moves in random direction
        • 1. Re: bounce
          blemmo Level 1
          Hi,

          check out the hitTest method of the MovieClip class:
          if (mc1.hitTest(mc2)){
          // mc1 hit mc2
          }

          To move in a random direction away from mc2, check the direction mc1 was going. If it went from left to right (e.g. mc1._x += 5), it will bounce off into the negative x direction, similar the other way around. So for the first case, you could use this:
          if (mc1.hitTest(mc2)){
          mc1._x -= 5+Math.random()*5 // moves away a random number between 5 and 10 in x direction
          if (Math.random() > 0.5){ // switches y direction (up or down)
          mc1._y -= Math.random()*5; // moves a random number between 0 and 5 upwards
          }
          else {
          mc1._y += Math.random()*5; // moves a random number between 0 and 5 downwards
          }
          }

          hth,
          blemmo