Jump to content

Player Slide When Changing Directions


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 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...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...