Workshop › Endless Runner › Step 6 of 19
Good platform games let you control the jump: hold the key for a high jump, tap it for a short hop. When the key is let go while still rising fast, the upward speed is cut to -4.
```js
const CUT = -4 // letting go early caps the upward speed at this
// Letting go early makes a short hop: cap the upward speed.
function endJump() {
if (runner.vy < CUT) runner.vy = CUT
}
document.addEventListener('keyup', (event) => {
if (event.key === ' ' || event.key === 'ArrowUp') endJump()
})
```vy < CUT means rising faster than 4 pixels a frame (more negative).keyup fires when a key is let go.JUMP, write CUT.jump, write the comment and endJump.keydown listener, write the keyup listener.Skills: Velocity and gravity, Keyboard and mouse input