1 Reply Latest reply on May 13, 2010 5:11 AM by rah02

    sinking under groung in flash game

    VicTropic

      Im making a flash game and I have a little error that might make my game crap. Basically the main character can jump around on a fixed screen and yspeed is added to the characters y and the yspeed is added 1 for every frame, like gravity. A while loop pushes the character up when he hits the ground, but for a split second, the character is under the ground. Is there a way to prevent this sink from happening, yeah and I know Im being a perfectionist:

       

       

            _root.onEnterFrame = function() {
        player1control();
        function ongrnd() {
         return lev.ground.hitTest(char._x, char._y, true);
        }
        function aboveground() {
         return lev.ground.hitTest(char._x, char._y+1, true);
        }
        function player1control() {
         walking=false;

          speed = 0;
         if (Key.isDown(Key.RIGHT)) {
          speed = 8;
          walking=true
          char.gotoAndStop(2);
          char._xscale = 100;
         }
         if (Key.isDown(Key.LEFT)) {
          speed = -8;
          walking=true
          char.gotoAndStop(2);
          char._xscale = -100;
         }
         if (Key.isDown(Key.UP) and !jumping) {
          yspeed -= 20;
          jumping = true;
         }
         if(!walking){
        char.gotoAndStop(1);
      }
         if (!aboveground()) {
          yspeed += 2;
          jumping = true;
         }
         while (ongrnd()) {
          char._y--;
          yspeed = 0;
          jumping = false;
         }
         char._y += yspeed;
        }

        • 1. Re: sinking under groung in flash game
          rah02

          Hi!

           

          This is more kind of a logic issue.

           

          I don't have an implementation correction, but i have a hint :-).

           

          You have to test when the character IS ABOUT TO hit the ground, not when he had hit the ground.

           

          If he is about to hit the ground (he is very near it), you "put" him on the ground and stop jumping.

           

          If you have the same gravity value, you can use it to determine where is the "is about to".

           

          I also didn't find a use for your loop. Maybe you could remove it if you implement the logic I suggested ;-).