blackhawx Posted September 18, 2018 Share Posted September 18, 2018 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 More sharing options...
jordanwallwork Posted September 19, 2018 Share Posted September 19, 2018 The linked example looks perfectly useable, did you try it or check the phaser 3 docs to see if the methods were still available? setAccelerationX / setAccelerationY instead of setVelocity s- https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.Body.html#acceleration apply drag to the body - https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.Body.html#drag constrain max velocity - https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.Body.html#maxVelocity__anchor blackhawx 1 Link to comment Share on other sites More sharing options...
blackhawx Posted September 19, 2018 Author Share Posted September 19, 2018 I'm making note of your advice when I run into similar situations in the future. Many thanks! Link to comment Share on other sites More sharing options...
Recommended Posts