Jump to content

Wall jumps


GooseZA
 Share

Recommended Posts

Hi all,

I'm trying to get wall jumping working in my little platformer. When the player jumps into a vertical wall, I want him to slide down slowly and then if jump is pressed while he's still on the wall, a horizontal jump in the opposite direction is performed.

I'm trying to check using body.onWall() to see if the player can walljump but this property only seems to be true for the initial contact. After that it is false. I assume on collision the player is probably being separated from the wall.

Any other ideas on how to do this?

Link to comment
Share on other sites

on the collision callback with the wall have an onWall var that you set to true, also save the x position of the sprite at that point. Then when the player presses the F key check if onWall is true, if it is check if the players current x position is equal to(or within a reasonable range) to the original x position when it hit the wall, if it is let him jump and if it isn't set onWall = false.

 

you could do this with 1 variable as well, only using the xPosition variable and setting it to -1 for false(or some other sentinel value if -1 is a valid x position in your game) and any number greater than 0 for positive, so it can be used to keep track of the x position and the onWall boolean.

 

this solution won't work for some cases though and will require a couple extra checks for edge cases, e.g when the player hits a wall then slides down off the bottom without changing position on the x-axis.

 

Not sure if this is the greatest solution but it's just what came to me and it sounds like it should work.

Link to comment
Share on other sites

on the collision callback with the wall have an onWall var that you set to true, also save the x position of the sprite at that point. Then when the player presses the F key check if onWall is true, if it is check if the players current x position is equal to(or within a reasonable range) to the original x position when it hit the wall, if it is let him jump and if it isn't set onWall = false.

 

This did the trick. When he was on wall, I saved his position and set canWallJump boolean to true. If jump was pressed after that, I checked if he was withing a reasonable range of the saved x Position and then let them jump

 

Thanks again =)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...