Source: https://mokxi.com/learn/path/physics-engine
Updated: 2026-11-20

All paths

# Write a physics engine

Build a 2D physics engine in C++ on an ESP32-C3: vectors, time steps, integration, collisions, springs, friction and rigid bodies, ending in a tilt-driven marble sandbox.

ESP32-C3-DevKitM-1 Free 7 lessons 6 h 4 chapters 2,348 XP Coding · Advanced +250 XP

0 of 7 done

Start the course free Vectors and time steps Lesson plan for teachers

What you will build

## 3 projects, built step by step

7 lessons in 4 chapters, about 6 hours on a simulated ESP32-C3-DevKitM-1. Free, in your browser, every step checked by the simulator.

Chapter 1 project

### Integration

Drop a ball and put two moons in orbit, and watch the order of two lines decide between a stable orbit and a moon spiraling off into space.
Open it in the simulator

Chapter 2 project

### Springs

Hooke's law and a damper: measure a spring's period against theory, find critical damping, and hang a swinging tether of eight masses from a station.
Open it in the simulator

Chapter 3 project

### Rigid bodies

Give a body an angle and a spin: moment of inertia, torque from an off-center kick, and contact impulses that make a solar panel tumble and settle.
Open it in the simulator

The map

## Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

## Motion

Vectors, fixed time steps, and why the order of two lines keeps a moon in orbit.

Open 212 XP

### Vectors and time steps

Write a 2D vector type with real C++ operators, move a probe through space one fixed time step at a time, and keep physics on its own clock.

0 of 4 steps

Start What is in it

Project Locked 500 XP

### Integration

Drop a ball and put two moons in orbit, and watch the order of two lines decide between a stable orbit and a moon spiraling off into space.

0 of 5 steps

5 questions, graded as you go.

Chapter 2

## Hits and springs

Impulses that keep momentum, and the force law behind every rope and shock absorber.

Locked 212 XP

### Collisions

Detect overlapping asteroids, push them apart, and bounce them with an impulse that keeps momentum exactly, and energy as much as restitution allows.

0 of 4 steps

Project Locked 500 XP

### Springs

Hooke's law and a damper: measure a spring's period against theory, find critical damping, and hang a swinging tether of eight masses from a station.

0 of 5 steps

4 questions, graded as you go.

Chapter 3

## Friction and rigid bodies

Stick and slip on a rolling deck, then bodies that turn as well as move.

Locked 250 XP

### Friction

Slide a crate to a stop, find the angle where static friction lets go, and ride a cargo crate on the deck of a ship rolling in a swell.

0 of 5 steps

Project Locked 424 XP

### Rigid bodies

Give a body an angle and a spin: moment of inertia, torque from an off-center kick, and contact impulses that make a solar panel tumble and settle.

0 of 4 steps

4 questions, graded as you go.

Chapter 4

## Boss

An MPU6050 tips a tray of marbles: the whole engine in one loop.

Locked 250 XP

### Boss: a tilt-driven sandbox

Tilt the board and a tray of marbles rolls downhill: an MPU6050 sets gravity, and integration, collisions, restitution and rolling do the rest.

0 of 5 steps

3 questions, graded as you go.

Syllabus

## Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

### Motion

- Vectors and time steps Write a 2D vector type with real C++ operators, move a probe through space one fixed time step at a time, and keep physics on its own clock.
- Integration Drop a ball and put two moons in orbit, and watch the order of two lines decide between a stable orbit and a moon spiraling off into space.

Chapter 2

### Hits and springs

- Collisions Detect overlapping asteroids, push them apart, and bounce them with an impulse that keeps momentum exactly, and energy as much as restitution allows.
- Springs Hooke's law and a damper: measure a spring's period against theory, find critical damping, and hang a swinging tether of eight masses from a station.

Chapter 3

### Friction and rigid bodies

- Friction Slide a crate to a stop, find the angle where static friction lets go, and ride a cargo crate on the deck of a ship rolling in a swell.
- Rigid bodies Give a body an angle and a spin: moment of inertia, torque from an off-center kick, and contact impulses that make a solar panel tumble and settle.

Chapter 4

### Boss

- Boss: a tilt-driven sandbox Tilt the board and a tray of marbles rolls downhill: an MPU6050 sets gravity, and integration, collisions, restitution and rolling do the rest.

Kits

## Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

### Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.
See every kit

Questions

## About Write a physics engine

Is Write a physics engine free?

Yes. All 7 lessons of Write a physics engine are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real ESP32-C3-DevKitM-1?

No. Every lesson runs on a simulated ESP32-C3-DevKitM-1 with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Write a physics engine take?

About 6 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: Integration, Springs and Rigid bodies.

Where do I start?

With "Vectors and time steps", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.
