Wall jumping collision detection anomaly
Posted
by
Nanor
on Game Development
See other posts from Game Development
or by Nanor
Published on 2014-05-14T10:00:01Z
Indexed on
2014/06/05
15:40 UTC
Read the original article
Hit count: 238
I'm creating a game where the player ascends a tower by wall jumping his way to the top. When the player has collided with the right wall they can only jump left and vice versa. Here is my current implementation:
if(wallCollision() == "left"){
player.setPosX(0);
player.setVelX(0);
ignoreCollisions = true;
player.setCanJump(true);
player.setFacingLeft(false);
} else if (wallCollision() == "right"){
player.setPosX(screenWidth-playerWidth*2);
player.setVelX(0);
ignoreCollisions = true;
player.setCanJump(true);
player.setFacingLeft(true);
} else{
player.setVelY(player.getVelY() + gravity);
}
and
private String wallCollision(){
if(player.getPosX() < playerWidth && !ignoreCollisions)
return "left";
else if(player.getPosX() > screenWidth - playerWidth*2 && !ignoreCollisions)
return "right";
else{
timeToJump += Gdx.graphics.getDeltaTime();
if(timeToJump > 0.50f){
timeToJump = 0;
ignoreCollisions = false;
}
return "jumping";
}
}
If the player is colliding with the left wall it will switch between the states left
and jumping
repeatedly due to the varible ignoreCollisions
being switched repeatedly in collision checks. This will give a chance to either jump as intended or simply ascend vertically instead of diagonally.
I can't figure out an implementation that will reliably make sure the player jumps as intended. Does anyone have any pointers?
© Game Development or respective owner