Files
nage/workshop/steps/03-integration/README.md
T
2026-09-04 13:57:52 +02:00

36 lines
1.2 KiB
Markdown

# 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`.
```sh
bun test workshop/steps/03-integration
```