build-a-physics-engine / lesson-08.md
Lesson 08 · Particles and integration

A body with position and velocity

The simplest thing a physics engine simulates is a point that has a place and a motion. Today you build the Body type that carries a position and a velocity, the state every later lesson updates.

The goal

Create a Body with a position and a velocity, both Vec2 values.

Start here - the target
TO DO
Scenario: A body holds its state
Givena new body at position {0, 0} with velocity {1, 2}
Whenits fields are read
ThenPosition is {0, 0} and Velocity is {1, 2}
Background

A physics simulation is a set of bodies, each with state that changes over time. The most basic state is where the body is (its position) and how fast and which way it is going (its velocity), both 2D vectors. Right now a Body is a bare point mass - no size, no mass, no spin - but this struct is the thing every future lesson thickens: mass and inverse mass, restitution, a shape, an angle and an angular velocity all get bolted on here.

Keep it a plain struct with exported fields so tests and later code can read and set its state directly. Starting from a point that only knows where it is and where it is heading keeps the first integration step - moving it by its velocity - as simple as it can be.

Make it work
// a point mass for now; mass, shape, and rotation come later
type Body struct {
Position Vec2
Velocity Vec2
}
CheckpointDONE
You have a Body that carries a position and a velocity. Commit and stop here.