1 Reply Latest reply on Oct 11, 2009 11:16 PM by ASnewbie

    How to stop a rectangle from going past an object after collision is detected?

    Ironhawk Productions

      Assuming, for a rectangle that is controlled by the user using the arrow keys, that I do the following:

       

      onClipEvent (enterFrame)

      {

           if (_root.WallsLevelOne.hitTest(character, true))

       

       

      Assuming that works in detecting the collision, what would I use to actually stop the rectangle from progressing through the wall?

        • 1. Re: How to stop a rectangle from going past an object after collision is detected?
          ASnewbie

          you would actually not do it that way in the first place

          What you would do is first create listener for the arrow keys press.

           

          Press should move and continue moving the rectangle. When pressed, you should gradually move it by adding a couple of x pixels or something. The keypress event can determine the collision within itself.

           

          here's a sample

          Assuming you have 2 items on the screen box1 and box 2 with box2 on the left hand side of box1. Please this script for box2.

           

           

          on(keyPress "<Right>"){

                  if(this.hitTest(_root.box2)){
                      trace("Sorry no more moving");

                  }
                  else{
                  this._x+=1;
                  }

          }

           

          BR

          Murtuza

          http://www.sowebme.com/murtaza