jonoxia / platform-game

untitled HTML 5 side-scroller
15 stars 5 forks source link

Character sometimes jumps higher than should be possible #2

Closed jonoxia closed 13 years ago

jonoxia commented 13 years ago

Not sure exactly how to trigger it, but I'm guessing that the jump function that imparts vertical velocity is somehow being invoked twice before you leave the ground, giving you double vertical velocity.

jonoxia commented 13 years ago

Actually you can get it to happen pretty reliably if you hold the spacebar down as you land from another jump.

jonoxia commented 13 years ago

Fixed in https://github.com/jonoxia/platform-game/commit/6e9a86161dc4f841463199337e93f056c8e49b74

satyreyes commented 13 years ago

If you hold down the spacebar only as you are about to land, you do not jump again immediately; the game waits to learn that this button is being held and not just pressed. At that point, your jump is of variable height. Moreover, in any case, you don't always get double vertical velocity; there are at least four discrete velocities you can get.

This suggests to me that holding down a key calls player.jump repeatedly before player.onGround can return false, perhaps because the heartbeat is substantially longer than how long a held-down space bar waits between presses. Shortening the heartbeat is the wrong answer, but disregarding a held-down space bar is the wrong answer too, since a player might like to be able to bounce while moving by holding down the space bar. Perhaps the right answer is to tell the jump function to set the player's velocity to -30, rather than decrementing it by 30.