7 Replies Latest reply on Dec 24, 2006 10:38 AM by kglad

    hitTest problems (again)

    tangytom
      Hi,

      sorry im back again but im pretty sure that with this problem solved i wont need to come back and bother you.

      so, i have a character MC and a wall MC, how can i make so that when the character walks into the wall, the character stops?

      Thank You.
        • 1. Re: hitTest problems (again)
          kglad Adobe Community Professional & MVP
          the code you're using to detect a wall collision is a poor for a number of reasons. this is one of them.

          by putting that hitTest() in its own onEnterFrame handler you'll need to use some variable/value to indicate the characters last movement prior to a wall collision and reverse it when your hitTest() is true.

          what you should do is put that hitTest() in the same loop that controls your character's movement. then you can easily reverse the character's movement.
          • 2. Re: hitTest problems (again)
            tangytom Level 1
            I have put the hit test code in with the characters movement but i need to know what line of code i need to use to stop the motion.
            • 3. Re: hitTest problems (again)
              kglad Adobe Community Professional & MVP
              that's not possible to answer without seeing what causes the character to move. did you write that code that causes your character to move?
              • 4. Re: hitTest problems (again)
                tangytom Level 1
                this is the code that makes the character move...

                onClipEvent (load) {
                movespeed = 3;
                }
                onClipEvent (enterFrame) {
                if (Key.isDown(Key.RIGHT)) {
                play();
                _rotation = 90;
                _x += movespeed;
                }
                if (Key.isDown(Key.LEFT)) {
                play();
                _rotation = 270;
                _x -= movespeed;
                }
                if (Key.isDown(Key.UP)) {
                play();
                _rotation = 0;
                _y -= movespeed;
                }
                if (Key.isDown(Key.DOWN)) {
                play();
                _rotation = 180;
                _y += movespeed;
                }
                if (Key.isDown(Key.RIGHT) && Key.isDown(Key.UP)) {
                _rotation = 45;
                }
                if (Key.isDown(Key.LEFT) && Key.isDown(Key.UP)) {
                _rotation = 315;
                }
                if (Key.isDown(Key.RIGHT) && Key.isDown(Key.DOWN)) {
                _rotation = 135;
                }
                if (Key.isDown(Key.LEFT) && Key.isDown(Key.DOWN)) {
                _rotation = 225;
                }
                onEnterFrame = function () {
                if (_root.wall.hitTest(_root.char1)) {
                _root.msgbox = "the door is locked.";
                } else {
                _root.msgbox = "";
                }
                };
                }
                I want the character to stop as well as having the msg displayed when it hits the wall

                Thank You
                • 5. Re: hitTest problems (again)
                  kglad Adobe Community Professional & MVP
                  use:

                  • 6. Re: hitTest problems (again)
                    tangytom Level 1
                    Thank You, it works now
                    • 7. Re: hitTest problems (again)
                      kglad Adobe Community Professional & MVP
                      you're welcome.