Hi @Adele welcome to html5gamedevs 😄. Without seeing the context of your code I cannot help that much. But, I will give it a try. This is how I would implement a double jump on my game.
// create a variable canDoubleJump
function update() {
if (this.keys.left.isDown) {
this.body.setAccelerationX(-1000);
player.anims.play('left',true);
} else if (this.keys.right.isDown) {
player.body.setAccelerationX(1000);
player.anims.play('right',true);
} else {
player.anims.play('idle',true);
player.body.setAccelerationX(0);
}
const didPressJump = Phaser.Input.Keyboard.JustDown(this.keys.up);
// player can only double jump if the player just jumped
if (didPressJump) {
if (player.body.onFloor()) {
// player can only double jump if it is on the floor
this.canDoubleJump = true;
player.body.setVelocityY(-100);
} else if (this.canDoubleJump) {
// player can only jump 2x (double jump)
this.canDoubleJump = false;
player.body.setVelocityY(-100);
}
}
}