nape-js

Fully typed 2D physics engine for TypeScript & JavaScript — modern rewrite of Nape

Rigid bodies • Circles, Polygons & Capsules • Constraints • Fluid simulation • Collision callbacks • Raycasting & spatial queries • Fracture • Soft body • Deterministic multiplayer • Serialization • Web Worker support — tree-shakeable, zero dependencies, ~27 KB gzip.

npm install @newkrok/nape-js

Interactive Demos

Click/drag on the canvas to interact. Pick a demo below. Physics Game

Loading engine…
FPS: — Bodies: — Step: —
Source Code

Benchmarks

Measured in your browser right now. Each test runs the physics step() in a tight loop and reports the median time per step.

Press the button to start.

Why nape-js?

nape-js is one of the few 2D physics engines for JavaScript and TypeScript that ships rigid body dynamics, joints (PivotJoint, DistanceJoint, WeldJoint, AngleJoint, MotorJoint, LineJoint, PulleyJoint, SpringJoint), fluid buoyancy, fracture, soft body, raycasting and convex sweeps, a built-in character controller, deterministic stepping for multiplayer rollback, binary serialization, replay recording, and an off-thread Web Worker bridge — all in a single tree-shakeable ESM bundle (~27 KB gzip), with full TypeScript types and zero DOM dependencies.

Looking for an alternative to Box2D, Matter.js, Planck.js, or Rapier? Run the in-browser benchmark to compare them head-to-head, or jump into the interactive examples — physics demos and playable mini-games (platformer, MOBA, tower defense, slingshot, pinball, top-down shooter).

API at a Glance

Core

  • Space — physics world
  • Body — rigid body
  • Vec2 — 2D vector
  • AABB — bounding box

Shapes