0 Replies Latest reply on Sep 20, 2008 3:46 PM by shintashi

    Collision Detection for MC inside MC

    shintashi Level 1
      Ok, so here's what I've got inside the first frame (the second frame just has a stop(); and go back button)

      quote:


      stop();
      hp2 = 300;
      var x:Number = 20;
      var mySpeed:Number = 5;

      onEnterFrame = function() {

      if (Key.isDown(Key.SHIFT)) {
      thrust = 7;
      } else {
      thrust = 2;
      }


      spin_key=(Key.isDown(Key.CONTROL));
      left_arrow=(Key.isDown(Key.LEFT));
      right_arrow=(Key.isDown(Key.RIGHT));
      spin_left = (spin_key) && (left_arrow);
      spin_right = (spin_key) && (right_arrow);


      if (spin_left){
      saber_mc._rotation -=10;
      }

      if (spin_right){
      saber_mc._rotation +=10;
      }




      if(Key.isDown(Key.getCode()) ) {
      switch(Key.getCode()) {
      case Key.UP: saber_mc._y -=mySpeed * thrust; break;
      case Key.DOWN: saber_mc._y +=mySpeed * thrust; break;
      case Key.LEFT: saber_mc._x -=mySpeed * thrust; break;
      case Key.RIGHT: saber_mc._x +=mySpeed * thrust; break;
      }
      }



      if (redbeam.saber_mc.hitTest(_root.victim_mc)) {
      _root.hp2-x;
      }

      // if(saber_mc.red_beam.hitTest(victim_mc)) {
      // _root.hp2-x;
      // }




      }





      I've also got four MCs inside the first frame:

      1. a target mc (victim)

      2. a handle mc (for the light saber) with the following code
      quote:


      onClipEvent(enterFrame){

      red=(Key.isDown(Key.SPACE));
      yellow=(Key.isDown(Key.UP));
      blue=(Key.isDown(Key.DOWN));
      purple = (red) && (blue);
      orange = (red) && (yellow);


      if (purple){
      this.gotoAndPlay("beam_on");
      }

      if (orange){
      this.gotoAndPlay("beam_off");
      }






      }


      3. a beam MC that appears in a frame inside the handle frame (selected or deselected by handle script above)

      4. an hp MC that is supposed to shrink when the target is struck by the beam, and when the hp MC is reduced beyond zero, the swf is supposed to move to the second frame.

      ~~~~~

      What I don't get is why the collision detection between the internal beam mc and the target mc works, but the hp bar doesn't get effected when swapping out the "gotoAndPlay" with "_root.hp2-x;"