2 Replies Latest reply on Feb 10, 2014 4:46 AM by Roefl

    Flash Action Script hitTest Change Variable

    WaltMichaelW

      Hello! I am making a flash game which is my own take on Pacman.  I at trying to make a wall that when the character hits, the character doesn't move at all.  When I put code on the wall itself, the character would hit it, then move forward 10 pixels while the key was pressed and spring back 10 pixels when it wasn't pressed.  Is there any way to make something completely solid? This is the code I was using before. 

       

      onClipEvent (enterFrame) {

                if (this.hitTest(_root.char))

                {

                          _root.char._x += 10;

                }

      }

       

      The code on the character (char) was

       

      onClipEvent (enterFrame) {

                var a_variable = 10;

                if (Key.isDown(Key.LEFT))

                {

                          this._x -= a_variable;

                          _root.char.gotoAndStop(2);

                }

                else if (Key.isDown(Key.RIGHT))

                {

                          this._x += a_variable;

                          _root.char.gotoAndStop(1);

                }

                else if (Key.isDown(Key.UP))

                {

                          this._y -= a_variable;

                          _root.char.gotoAndStop(3);

                }

                else if (Key.isDown(Key.DOWN))

                {

                          this._y += a_variable;

                          _root.char.gotoAndStop(4);

                }

      }

       

      I am wondering if there is a way to set the variable a_variable to 0 when the character hits the wall. 

       

      Thanks.

      ~Walt