Files
nage/workshop/steps/03-integration/README.md
T
2026-07-11 17:48:28 +02:00

1.2 KiB

Step 03 — Integration (moving over time)

Concept

"Integration" sounds like calculus, but the version we need is one line. An object has a position and a velocity. Each frame we advance the position by the velocity, scaled by how much time passed:

newPosition = position + velocity * delta

That's add(pos, scale(vel, delta)). This single step is the beating heart of every game's update loop.

Why delta?

delta is the number of milliseconds since the last frame. Frames are not evenly spaced — a busy frame takes longer. If you moved a fixed amount per frame instead of per millisecond, your game would run faster on a fast computer and slower on a slow one.

By storing velocity as units-per-millisecond and multiplying by delta, the distance travelled over a given stretch of real time is the same no matter how the frames are chopped up. That property is called framerate independence, and one of the tests below proves it: moving once with delta = 16 lands in the same place as moving sixteen times with delta = 1.

Task

Implement integrate(pos, vel, delta) in motion.ts.

bun test workshop/steps/03-integration