Jump to content

Best way to get objects to slightly slide before stopping


blackhawx
 Share

Recommended Posts

I ran across the following article online in getting objects to slightly slide as we press LEFT or RIGHT on keyboard. - https://gamemechanicexplorer.com/#platformer-3

I'm not sure if that source is outdated or not, but is there a Phaser 3.12+ version of what that article is describing?

For my game, I have the following in my update function which appears to be working in getting my player to go left and right.  But player stops instantly due to the `setVelocityX(0)` that is set in place.  How could I enhance this script?

 


function create() {
...
//the initial cursor object for keyboard controls
 cursors = this.input.keyboard.createCursorKeys();
...
}



function update(time,delta) {

  if (cursors.left.isDown) // if the left arrow key is down
  {
      player.body.setVelocityX(-200); // move left
      player.anims.play('walk', true); // play walk animation
      player.flipX= true; // flip the sprite to the left
  }
  else if (cursors.right.isDown) // if the right arrow key is down
  {
      player.body.setVelocityX(200); // move right
      player.anims.play('walk', true); // play walk animatio
      player.flipX = false; // use the original sprite looking to the right
  } else {
    player.body.setVelocityX(0);
    player.anims.play('idle', false);
  }
  
  //player jumping
  if ((cursors.space.isDown || cursors.up.isDown) && player.body.onFloor())
  {
      player.body.setVelocityY(-500); // jump up
  }
}

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

The linked example looks perfectly useable, did you try it or check the phaser 3 docs to see if the methods were still available?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...