Fix for wall jump problem

Godot Version

4-4.stable

Question

I’m trying to implement a wall-jump mechanic in my game. The way I do it is by checking the player’s velocity.x. If it’s greater than or equal to 0, I adjust velocity.x to move the player away from the wall.

However, I’m facing an issue: If the player changes their input while wall-jumping, the velocity.x flips from positive to negative or from a negative to a posative. This causes the player to move back toward the wall instead of away from it, and the character ends up moving upward only without moving towards the wall, because the velocity is now going in the opposite direction.

Hi!

Wall jump is tricky, and it also depends on the feeling you want. Many platformers have wall jumping, but the actual implementations differ.
I believe there’s no absolute right way to do this kind of stuff, and sadly I don’t know any “clean” way (as these “game feel” problems don’t come with ready-to-use code patterns or something, it’s just a matter of adding many minor things to the player code), but here’s an idea.

You could try adding a timer after a wall jump, during which you ignore the player direction input. This will ensure that for a few moments (something short, like 0.1s maybe), you force the direction to be the jump direction. After the timer, if the player presses the opposite direction, you allow him to move back to the wall.
Another thing you could do to improve the feeling is not simply ignore player input while the timer is running, but reduce the input based on the timer’s current percentage. This way, if a player presses the opposition direction of the jump, he will jump but smoothly move back to the wall over time.

Let me know if that helps!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.