Sign in to follow this  
Adele

Double Jump Phaser 3

Recommended Posts

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');
}
 
}

Share this post


Link to post
Share on other sites

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 by geocine

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.