Hi all,
I'm in the middle of a platforming game. The problem is that every time my player lands on a platform, it sinks through like quicksand, and whenever it touches the bottom of the platform, it's just stuck there (will deal with bouncing off the left and the right after this is fixed). I've tried a lot of fixes, all without success. Hope you guys can help me on this. Thanks!
public void MovementSetup() { YPosition = getY(); if (Greenfoot.isKeyDown("Left")) { setRotation(0); move(-5); } if (Greenfoot.isKeyDown("Right")) { setRotation(0); move(5); } if (isInTheAir = true) { Gravity = 1; } if ((Greenfoot.isKeyDown("Up") || Greenfoot.isKeyDown("Space")) == true && numberOfJumps < 2) { JumpHeight = -17; numberOfJumps++; Greenfoot.delay(7); isInTheAir = true; } JumpHeight = JumpHeight + Gravity; Actor platformBelow = getOneObjectAtOffset(0, HeightToGround + 1, Platform.class); Actor platformAbove = getOneObjectAtOffset(0, -(HeightToGround + 1), Platform.class); Actor platformLeft = getOneObjectAtOffset(SideWidth + 1, 0, Platform.class); Actor platformRight = getOneObjectAtOffset(-(SideWidth + 1), 0, Platform.class); if (platformBelow != null) { if (JumpHeight > 1) { JumpHeight = 0; numberOfJumps = 0; isInTheAir = false; Gravity = 0; } } if (platformAbove != null) { if (JumpHeight > 0) { JumpHeight = 0; isInTheAir = true; GreenfootImage platformImage = platformAbove.getImage(); int BottomOfPlatform = platformAbove.getY() + platformImage.getHeight() / 2; YPosition = BottomOfPlatform + HeightToGround; } } } public void Movement() { setLocation (getX(), YPosition + JumpHeight); } public void JumpResets() { Actor platformBelow = getOneObjectAtOffset(0, HeightToGround + 1, Platform.class); if (getY() >= 749 || platformBelow != null) { YPosition = getWorld().getHeight() - HeightToGround; numberOfJumps = 0; } }