With Phaser (and following allong with the tutorials) jumping is super-easy with the provided Arcade physics module. However, it has the annoying-to-me fact that a player can only jump when they are "on" the ground due to the use of player-is-touching-down logic.
The code I am using is based on Game Mechanic Explorer, Platformer #4 and follows;
var canJump = this.player.body.touching.down;
if (canJump && this.upInputIsActive()) {
this.player.body.velocity.y = this.JUMP_SPEED;
}
I would like to enable a player be able to jump when they are really close to the ground but are not yet touching so that the re-jump/jump-as-landing is more fluid. As such, and the observation that the limit is caused by touching.down
of the player, my questions are;
Is it possible to determine the distance ("how high") the player is from the ground (which can be a platform) immediately below them? Then
canJump
is just a function of the distance, being true for very small values only.Can a virtual hit-box be extended around the player (that would travel-with the player) such that it's own
touching.down
could be used to detect this case? Is this approach better? The player sprite itself should not levitate off the ground or otherwise be effected.
The goal here is specifically to allow the player to jump just before they ought to be able to - so remembering an up key-press for a short duration of time, which may be viable, is not a solution I am seeking in this particular case.