Physics Guide

OpenReality includes a full rigid body physics engine with impulse-based constraint solving, GJK+EPA collision detection, and spatial hash broadphase.

# Adding Physics

Add physics to any entity with a ColliderComponent and a RigidBodyComponent. The physics system runs automatically each frame.

physics_basic.jl

# Collision Shapes

Seven collision shape types for different use cases. Simple shapes (AABB, Sphere) are fastest; ConvexHull and Compound are more accurate but more expensive.

shapes.jl

# Body Types

Three body types control how the physics engine treats an entity.

body_types.jl

# Solver Pipeline

The physics engine runs a 7-phase pipeline each step:

1.Update world-space inertia tensors
2.Apply gravity, reset grounded flags
3.Broadphase — spatial hash grid finds candidate pairs
4.Narrowphase — GJK+EPA computes contacts for each pair
5.Solve velocity constraints — PGS impulse solver with warm starting
6.Integrate positions
7.Update grounded status, sleeping (islands), CCD

# Joint Constraints

Connect entities with joints to create mechanical systems. Joints constrain the relative motion between two bodies.

constraints.jl

# Trigger Volumes

Triggers detect overlap without applying physical forces. Useful for checkpoints, damage zones, and event areas.

triggers.jl

# Raycasting

Cast rays into the physics world for hit detection, line-of-sight checks, and picking.

raycast.jl

# Continuous Collision Detection

Fast-moving objects can tunnel through thin geometry. CCD performs swept tests between frames to prevent this.

ccd.jl