Workshop › Pinball › Step 37 of 42
The longer you hold, the harder the launch. While the ball waits and the key is held, charge grows from 0 to 1 in
about a second; letting go launches at a speed between 13 and 19.
```js
let charge // 0 to 1 while the launcher is held
charge = 0
if (pressed.launch) charge = Math.min(1, charge + 0.02)
ball.vy = -(13 + 6 * charge)
charge = 0
```newBall resets charge for each new ball.Math.min(1, ...) stops it at 1 (50 frames, under a second).launch turns the charge into speed and empties the spring.let pressed write let charge.newBall, under the ball = ... line, write charge = 0.update's ready block, under the flippers line, write the charge line.launch, replace ball.vy = -16 with the two lines.Skills: Velocity and gravity, Keyboard and mouse input
← Launch on letting go Show the spring →