Physics & Collision

Overview

The physics system integrates Jolt Physics for rigid body simulation with automatic Transform synchronization. It supports a unified Collider component with box, sphere, and capsule shapes, plus optional debug wireframe outlines.

Adding Physics in the Editor

To make an entity physically simulated:

  1. Select the entity in the Scene Hierarchy
  2. In the Inspector, click Add Component > RigidBody
  3. Choose a body type: Static, Dynamic, or Kinematic
  4. Add a collider: Add Component > Collider
  5. Choose a shape: Box, Sphere, or Capsule
  6. Configure the physics properties in the Inspector

Components

RigidBody

FieldTypeDefaultDescription
typeStatic / Dynamic / KinematicDynamicBody type
massfloat1.0Mass in kg (Dynamic only)
linearDampingfloat0.05Linear velocity damping
angularDampingfloat0.05Angular velocity damping
restitutionfloat0.3Bounciness (0 = no bounce, 1 = full bounce)
frictionfloat0.5Surface friction
gravityFactorfloat1.0Gravity multiplier (0 = no gravity)
freezePositionX / Y / Z checkboxesoffFreeze movement on specific axes
freezeRotationX / Y / Z checkboxesoffFreeze rotation on specific axes

Collider

A single Collider component supports three shapes, selected via a dropdown:

FieldTypeDefaultDescription
shapeBox / Sphere / CapsuleBoxCollider shape type
halfExtentXfloat (Box only)0.5Half-width on X axis
halfExtentYfloat (Box only)0.5Half-height on Y axis
halfExtentZfloat (Box only)0.5Half-depth on Z axis
radiusfloat (Sphere / Capsule)0.5Sphere or capsule radius
halfHeightfloat (Capsule only)0.5Half the height of the cylindrical section
offsetX/Y/Zfloat0.0Offset from entity position
showOutlineboolfalseShow green debug wireframe

The Show Outline checkbox renders a green wireframe matching the collider shape, useful for debugging collision bounds.

Body Types

TypeDescription
StaticDoes not move. Use for floors, walls, and terrain.
DynamicFully simulated. Affected by gravity, forces, and collisions.
KinematicMoved by code/animation, not by physics. Still collides with dynamic bodies.

Integration Notes

  • Physics runs with a fixed timestep of 1/60s using an accumulator pattern
  • Transform is automatically synced from physics for Dynamic/Kinematic bodies
  • Bodies are created lazily when entities with RigidBody + Transform are detected
  • If no collider is attached, a default unit box is used
  • All physics components are editable in the Inspector and serializable
  • Physics steps in Engine::BeginFrame(), before rendering
  • Old scenes with separate BoxCollider/SphereCollider/CapsuleCollider components are automatically migrated to the unified Collider on load