Adele Posted March 25, 2020 Share Posted March 25, 2020 Hi, I'm new to developing games with Phaser3. I am going crazy, for days I have been looking for a way to do a 'double jump'. and I can't ... I found many questions similar to this one here, but none gave me a concrete solution ... I would like the player to double jump if I double-click the 'up' cursor. Please help me. function update() { if (cursors.left.isDown) { player.setVelocityX(-130); player.anims.play('left', true); } else if (cursors.right.isDown) { player.setVelocityX(130); player.anims.play('right', true); } else { player.setVelocityX(0); player.anims.play('idle', true); } if (cursors.up.isDown && player.body.touching.down) { layer.setVelocityY('100'); } } Link to comment Share on other sites More sharing options...
geocine Posted March 28, 2020 Share Posted March 28, 2020 (edited) 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); } } } Edited March 28, 2020 by geocine Link to comment Share on other sites More sharing options...
supertommy Posted April 6, 2020 Share Posted April 6, 2020 The answer from @geocine should solve this just fine ? Here's another solution that can be used to implement triple, quadruple, etc jump as well (if so desired ?) This is a video of me implementing it in real time: Link to comment Share on other sites More sharing options...
Recommended Posts