lobsterhands Posted May 27, 2014 Share Posted May 27, 2014 I'm trying to get my player controls to be more responsive. Currently, when I stop inputting directions, the player stops quickly. However, if I try to change directions quickly, switching immediately from left-to-right (or vice versa) my player slides a bit in the original direction. How can I fix this? See the game here: http://lyledenman.com/portfolio/games/worldhopper/index.html Controller code below:*Note playerHigh and playerLow describe the player's coordinates as near the top or the bottom of the rectangle. onLeft and onRight describe whether the player is touching the side of the rectangle.function leftInputIsActive() { var isActive = false; isActive = this.game.input.keyboard.isDown(Phaser.Keyboard.LEFT); isActive |= (this.game.input.activePointer.isDown && this.game.input.activePointer.x < this.game.width/4); return isActive; } function rightInputIsActive() { var isActive = false; isActive = this.game.input.keyboard.isDown(Phaser.Keyboard.RIGHT); isActive |= (this.game.input.activePointer.isDown && this.game.input.activePointer.x > this.game.width/2 + this.game.width/4); return isActive; } if (rightInputIsActive() && !playerLow) { this.player.body.acceleration.x = this.ACCELERATION; } else if (rightInputIsActive() && playerLow) { this.player.body.acceleration.x = -this.ACCELERATION; } else if (leftInputIsActive() && !playerLow) { this.player.body.acceleration.x = -this.ACCELERATION; } else if (leftInputIsActive() && playerLow) { this.player.body.acceleration.x = this.ACCELERATION; // } else if (leftInputIsActive()) { // this.player.body.acceleration.y = this.ACCELERATION; // } else if (rightInputIsActive()) { // this.player.body.acceleration.y = -this.ACCELERATION; } else if (leftInputIsActive()) { this.player.body.acceleration.y = this.ACCELERATION; } else if (rightInputIsActive()) { this.player.body.acceleration.y = -this.ACCELERATION; } else { this.player.body.acceleration.x = 0; } if ((leftInputIsActive() && onLeft) || (rightInputIsActive() && onRight)) { this.player.body.acceleration.y = this.ACCELERATION; } else if ((leftInputIsActive() && onRight) || (rightInputIsActive() && onLeft)) { this.player.body.acceleration.y = -this.ACCELERATION; } else { this.player.body.acceleration.y = 0; } Link to comment Share on other sites More sharing options...
lewster32 Posted May 27, 2014 Share Posted May 27, 2014 Try setting the player's velocity.x = 0 to instantly stop it, otherwise you'll just have to fine tune your acceleration and damping as explained in this example. Link to comment Share on other sites More sharing options...
lobsterhands Posted May 28, 2014 Author Share Posted May 28, 2014 Thanks, Lewster. I guess I'll be tweaking it a bit. Link to comment Share on other sites More sharing options...
Recommended Posts