Jump to content

Player Slide When Changing Directions


lobsterhands
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

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