Workshop › Pool › Step 28 of 33
Hit a ball hard and at an angle, and it can go off in the wrong direction: at power 16 a ball moves 16 pixels a frame,
so by the time we notice two balls touch they may overlap a lot, and the line between their centres is no longer the one at
first contact. The fix: split each frame into SUB smaller steps.
```js
const SUB = 8 // physics steps per frame, so fast balls cannot jump through each other
b.x += b.vx / SUB
b.y += b.vy / SUB
for (let i = 0; i < SUB; i++) step()
```update runs eight steps per frame, so a frame still moves the full
velocity.MAX_POWER write SUB.step, divide the velocities by SUB.update, replace step() with the for line.Skills: Velocity and gravity, Collision detection
← Pull back and let go Predict the hit →