3 Replies Latest reply on Jun 15, 2010 7:44 AM by kglad

    hitTest trying to stop something moving

    DOMIN8ER258

      ok here is the scene

       

      _root.playa

      _root.playa.feetMC

      _root.corneria

      _root.corneria.limitsMC

       

      Now, what I want is when _root.playa.feetMC hits, or is ontop of _root.corneria.limitsMC it stops moving

       

      To help here is the code for my playaMC to make hime move

       

      onClipEvent (enterFrame) {
          movement = 2.5;
          if (Key.isDown(Key.DOWN)) {
              if (Key.isDown(Key.RIGHT)) {
                  movement = 0;
              }
              if (Key.isDown(Key.LEFT)) {
                  movement = 0;
              }
              this.gotoAndStop(1);
              _root.playa.downMC.play();
              _root.corneriaMC._y -= movement;
          }
          if (Key.isDown(Key.UP)) {
              if (Key.isDown(Key.RIGHT)) {
                  movement = 0;
              }
              if (Key.isDown(Key.LEFT)) {
                  movement = 0;
              }
              this.gotoAndStop(2);
              _root.playa.upMC.play();
              _root.corneriaMC._y += movement;
          }
          if (Key.isDown(Key.LEFT)) {
              this.gotoAndStop(3);
              _root.playa.leftMC.play();
              _root.corneriaMC._x += movement;
          }
          if (Key.isDown(Key.RIGHT)) {
              this.gotoAndStop(4);
              _root.playa.rightMC.play();
              _root.corneriaMC._x -= movement;
          }
      }

       

      any help appreciated!

        • 1. Re: hitTest trying to stop something moving
          kglad Adobe Community Professional & MVP

          you shouldn't attach code to objects.  but if you want to continue to use that, try:

           


           

          onClipEvent (enterFrame) {

          if(!hittestPositive){
              movement = 2.5;
              if (Key.isDown(Key.DOWN)) {
                  if (Key.isDown(Key.RIGHT)) {
                      movement = 0;
                  }
                  if (Key.isDown(Key.LEFT)) {
                      movement = 0;
                  }
                  this.gotoAndStop(1);
                  _root.playa.downMC.play();
                  _root.corneriaMC._y -= movement;
              }
              if (Key.isDown(Key.UP)) {
                  if (Key.isDown(Key.RIGHT)) {
                      movement = 0;
                  }
                  if (Key.isDown(Key.LEFT)) {
                      movement = 0;
                  }
                  this.gotoAndStop(2);
                  _root.playa.upMC.play();
                  _root.corneriaMC._y += movement;
              }
              if (Key.isDown(Key.LEFT)) {
                  this.gotoAndStop(3);
                  _root.playa.leftMC.play();
                  _root.corneriaMC._x += movement;
              }
              if (Key.isDown(Key.RIGHT)) {
                  this.gotoAndStop(4);
                  _root.playa.rightMC.play();
                  _root.corneriaMC._x -= movement;
              }

          }

          if(_root.playa.feetMC.hitTest( _root.corneria.limitsMC)){

          hittestPositive=true;

          }

          }

           

           

          • 2. Re: hitTest trying to stop something moving
            DOMIN8ER258 Level 1

            Maybe im not doing this right, the new code didnt work. Here is a much more detailed version.

             

            I have an MC called playa, in this MC I have another called feetMC.

            I also have an MC called corneriaMC, and in this I have an MC called limitsMC

             

            the feetMC is a rectangle, but the limitsMC is a completely irregular shape.

             

            I think my problem is the irregular limitsMC part of it.

            • 3. Re: hitTest trying to stop something moving
              kglad Adobe Community Professional & MVP

              hittest determines whether the bounding rectangles are colliding.  if you want to test against a non-rectangular shape you must use a shape-based hittest.  you can use gskinner's collisiondetection class.