Skip to content

Box2D

A 2D physics engine in C that game developers embed to simulate bodies, collisions, and joints.

Stars
10.5k
Forks
1.8k
Licence
MIT
Language
C
Last update
7 days ago
Type
Library

What it is

Box2D is a library that calculates how 2D shapes move, bump, slide, and rotate, so a game does not have to write that math itself. Developers add bodies and shapes to a world, step the simulation each frame, and read back positions. It is written in portable C17 and is aimed at games that need collision detection, joints, and character movement in two dimensions.

  • Add rigid bodies with collision shapes such as circles, polygons, and capsules to a 2D game world
  • Use joints such as revolute, prismatic, and wheel joints to build hinges, sliders, or vehicles
  • Run ray casts and overlap queries to detect what a projectile or sensor hits
  • Record a play session as a .b2rec file and replay it with the samples viewer

Great for

  • Game developers building 2D games who want a ready-made physics solver
  • Developers who work in C, or in languages that can call C such as Zig and Swift
  • Projects with many bodies that need good performance
  • Developers who need deterministic simulation, replay, or snapshot and restore

Not ideal for

  • Developers who need 3D physics, since this engine only covers 2D
  • Beginners who want a visual editor or drag-and-drop tool, because the README describes only a code API and sample programs
  • Projects that want to contribute code directly, because the README asks people not to submit pull requests
Step-by-step guide: how to use Box2DInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Clone and build from source

    You'll need: CMake · git · A compiler that supports C17 (Visual Studio on Windows, Make on Linux, Xcode on macOS per the presets)

    Clone the repository

    git clone https://github.com/erincatto/box2d

    Configure and build with Linux preset

    cmake --preset linux-release

    Build with Linux preset

    cmake --build --preset linux-release
  2. 2

    Run it

    • Clone the repository and open it in a terminal
    • Configure the build with the preset for your platform
    • Build the project with the matching build preset
    • Run the samples program from the build/bin folder to see working demos
  3. 3

    Get the most out of it

    • Use the samples app to explore the many demos for features and performance
    • Open .b2rec recordings in the replay viewer to inspect a simulation frame by frame
    • Define BOX2D_DISABLE_SIMD if you need to turn off SIMD math
    • Use the Zig or Swift package setup if your project already uses those languages

Downloads

Strengths

  • The README lists a broad feature set covering collision, joints, character movers, and events
  • Written in portable C17 and runs on Windows, Linux, and Mac according to the README
  • Released under the MIT license, which permits commercial use

Trade-offs

  • The README is focused on build steps and feature lists, so it gives little guidance on game design or physics theory
  • Getting a first result requires compiling C code or using a language binding, which is a barrier for non-programmers
  • Documentation is pointed to an external manual that this analysis did not review

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.