[SOLVED] Allow jump based on time after touching platform

I’m trying to polish my player movement before moving on to more level design. One thing I want to do is allow the player to still be able to jump shortly after leaving a platform. For example, if I press my jump key 2 milliseconds after leaving the platform, I still want to be able to jump. Right now it can sometimes feel like there is no feedback if the jump isn’t timed just right.

What is the best way to check if the player has left the platform and then based on either a specific distance from the platform (probably the best case) or a time frame in milliseconds and then set my Jump mechanic to fire based on that criteria? I’ve cut out and cleaned up a small snippet of code to show my jump conditional

if (this.player.body.touching.down && this.scene.player.jumpCount === 0 && Phaser.Input.Keyboard.JustDown(this.scene.cursors.jump)) {
        this.player.setVelocityY(-925);
        this.scene.player.jumpCount++;
    } else if (this.player.body.touching.down) {
        this.scene.player.jumpCount = 0;
    }
}

Hey Ben,
You could probably add an overlap object that is larger than your collider and detect if that is touching.

I’ve never modified the size of an overlap object, I’ll look into this and give it a try.

Hi,

I’m not sure if this is what you want but you could remove the touching down check inside the if() statement as that way they will always be able to jump once before having to land to reset the jump counter. The drawback to this though is if they for example fall off the platform they will still be able to make a jump as they are falling down. If this is not a problem it could be an easy solution.
Sorry if this is not much help :slight_smile:

1 Like

That may actually work and not be a problem. I just need to make sure that doesn’t affect the game play negatively. Very good thought

Allowing the player to jump at any time or increasing the size of the platforms could feel unnatural or affect gameplay. Tolerance timers shouldn’t be hard to implement - set a variable if the player is touching the ground, then decrement the variable every frame (ideally, you should set its value in milliseconds and decrement it by the delta given to the update function) and allow the player to jump if that variable is positive. This would give the player small tolerance without heavily affecting the physics of the game.

1 Like

I appreciate the feedback. I agree with this, it definitely could. In the case of this particular game, the solution to not check for the player touching for the first jump works great! With my jump counter I have, it prevents players from jumping multiple times, this has a great arcade feel to it.

I will save your solution for whenever I need more realistic physics.