Command Palette

Search for a command to run...

Hectal
Phase 16: Physics and Small Games
3D Web · Exercise 2 of 4 PreviousNext
Advanced

A fixed-step accumulator

Write createFixedStepper(step, onStep). Its tick(delta) adds delta, capped at 0.25 s, to an accumulator, calls onStep() once per whole step it holds, and returns alpha (what is left, divided by the step).

What Check tests

  1. 30 frames of 1/30 s give 60 steps of 1/60 s
  2. Short frames accumulate: 4 frames of 1/240 s give 1 step
  3. A 2 s stall runs only 15 steps (the 0.25 s cap)
  4. tick returns alpha, the leftover share of a step

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.