Monograph · 11 · Physics
Systems · full depth
Physics
Simulation as a pluggable service: factory → backend → world step → component write-back → optional TLAS dirty. Rendering never steps Jolt itself.
Backend factory
- If Jolt compiled and preferred is jolt/auto/empty → try
JoltPhysicsBackend - On exception → log and fall through
- Else / always available:
NullPhysicsBackend(no-op, no crash)
Headless CI or machines without physics still run the renderer. “Microservice” isolation: physics failure must not take down the engine.
IPhysicsBackend surface
Abstract API covers: rigid body lifecycle, transforms, velocities, forces, sleep, shapes, CCD, 16-layer collision matrix, raycast/overlap/shape cast, contact callbacks (thread-safe queue), constraints (fixed/point/hinge/slider/cone/distance/six-DoF), heightfields, character controller. Handles are uint32_t with INVALID sentinels.
World config & state machine
PhysicsWorldConfig: gravity (default −9.81 y), timeStep 1/60, maxSubSteps, multithreading, sleeping, CCD, debug flags, maxBodies/constraints. Scene constructor builds a world and initializes with settings.
States: STOPPED · RUNNING · PAUSED · STEPPING. Hosts call play/pause/step/stop (and GDScript facades mirror this).
Step workflow
- If not running/stepping, return
- Accumulate time; for each substep:
- Force registry: gravity, springs, drag, volumes, fields…
- Backend integrate contacts / constraints
- Drain contact begin/persist/end events to listeners
- Write transforms back to RigidBody / PhysicsComponent / actors
- Optional profiler / debug draw data
Bodies, shapes, layers
Types: dynamic, static, kinematic. Shapes: box, sphere, capsule, cylinder, triangle mesh, heightfield. Layers 0–15 (DEFAULT, STATIC, CHARACTER, TRIGGER, PROJECTILE, …) with pair enable/disable. CCD for fast movers. Mass, friction, restitution, damping, gravity scale.
Forces & constraints
Force generators register on bodies each step (not one-shot impulses only). Constraints build mechanisms: doors (hinge), ragdolls, vehicles. Motors, limits, breakable joints for gameplay.
Character & queries
Capsule character controller with ground state classification. Queries: raycast closest/all, sphere/box overlap, shape casts — layer masks filter results. Grab/throw helpers sit above springs/constraints in higher-level APIs.
Sync to scene / GPU
- Actor world matrices updated from bodies
- Deferred draws use new model matrices automatically if upload path reads components each frame
- RT: TLAS instances need update/rebuild if transforms moved — trunk favors static BLAS; dynamic policy is host responsibility
backend_factory.cppJolt or nullphysics_backend.hppFull contractjolt/jolt_backend.*Production implworld/physics_world.*Step · stateforces/*Generatorscomponents/physics_component.*Actor bindDesign units in this module
Each card is a focused design page (what / how / why + sources). Full tree: Sitemap.
Backend plugin
IPhysicsBackend, factory, null fallback, Jolt.
PhysicsWorld
Config, state machine, step, body registry.
Bodies & shapes
RigidBody, all shape types, factory, PhysicsComponent.
Force generators
Registry, gravity, spring, drag, volumes, fields, presets.
Physics materials
Friction/restitution style materials.
Physics math & constants
Shared scalars, clamp helpers, math utils.
Force debugger
Debug visualization hooks.