4 Replies Latest reply: Apr 15, 2013 11:39 PM by moccamaximum RSS

    Character falls through the ground


      I have created gravity in a little platform game, and it works, however my character ignores all the hitTest code and falls through the floor... and I can't move her because she then just disappears... How do I preven her from faling through the ground so I can actually move her around the screen..


      I'm using as3 in Flash CS6


      Any help would be greatly appreciated 



        • 1. Re: Character falls through the ground
          Ned Murphy MVP

          Show the relevant hitTest code and indicate where it doesn't appear to obey what you think it should.

          • 2. Re: Character falls through the ground
            Bombza Community Member

            Well I'm slightly confused... I created an array to hold all the diferent levels in the platform, and called the hitTest sort of thing from that, see if you can understand it:


            This is the array that holds the seven latform levels


            var level:Array = new Array ();

            for (var i=0; i<numChildren; i++) {

                      if (getChildAt is Platform) {

                                level.push (getChildAt(i).getRect(this));




            here is the vertical hit test things


            speedY += 1;

                      girl.y += speedY;

                      var jumpable = false;

                      for (i=0; i < level.length; i++) {

                                if (girl.getRect(this).intersects(level[i])) {

                                          if (speedY > 0) {

                                                    girl.y = level [i].top + girl.height/2;

                                                    speedY = 0;

                                                    jumpable = true;


                                          if (speedY < 0) {

                                                    girl.y = level [i].bottom - girl.height/2;

                                                    speedY *= -0.5;


                                          speedX = 0;




            I have also found that the girl doesn;t seem to move to the right either...

            • 3. Re: Character falls through the ground
              Ned Murphy MVP

              Why don't you just use the hitTestObject() method?


              Are you sure that your array holds anything.  Try tracing it to make sure.


              There is no code there to move the girl in the x direction,.

              • 4. Re: Character falls through the ground
                moccamaximum Community Member

                Make sure that you put the the relevant hitTest Logic inside an Enter_frame Event listener and that you attach that listener to the stage, make also sure you have access to stage when you do that.