Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Physics

GoudEngine provides 2D and 3D rigid body physics through the Rapier physics library.

Providers

ProviderBackendDimensions
Rapier2DPhysicsProviderrapier2d2D
Rapier3DPhysicsProviderrapier3d3D
NullPhysicsProvidernonefallback

PhysicsWorld

The PhysicsWorld resource controls simulation parameters:

  • Timestep: fixed at 1/60s by default
  • Iterations: 8 velocity, 3 position (configurable)
  • Gravity: Vec2 for 2D, Vec3 for 3D
  • Time scale: 0.0–10.0 range for slow-motion or fast-forward
  • Sleeping: idle bodies stop simulating to save CPU

The simulation uses a fixed-timestep accumulator pattern for deterministic behavior regardless of frame rate.

Components

RigidBody

Attached to entities that participate in physics simulation.

FieldTypeDescription
body_typeRigidBodyTypeDynamic, Kinematic, or Static
velocityVec2Linear velocity
massf32Body mass
gravity_scalef32Per-body gravity multiplier
angular_velocityf32Rotational speed
linear_dampingf32Velocity decay per frame
angular_dampingf32Angular velocity decay
can_sleepboolWhether the body can enter sleep state

Collider

Defines collision geometry attached to a body.

FieldTypeDescription
shapeColliderShapeCircle, Box (AABB), Capsule, or Polygon
frictionf32Surface friction coefficient
restitutionf32Bounciness (0 = no bounce, 1 = full)
is_sensorboolTrigger-only (no physical response)
layeru32Collision layer bitmask
masku32Which layers this collider interacts with

Collision Shapes

  • ColliderShape::Circle(radius) — circle with given radius
  • ColliderShape::Aabb(half_extents) — axis-aligned box
  • ColliderShape::Capsule(radius, height) — capsule (rounded box)
  • ColliderShape::Polygon(vertices) — convex polygon from vertex list

Layer Filtering

Layer-based collision filtering uses bitmasks on Collider. A body’s layer is compared against the other body’s mask. If the bitwise AND is zero, the pair is skipped before narrow-phase collision detection.

FFI

Physics FFI functions are in goud_engine/src/ffi/physics/. Key functions:

  • goud_physics_create() / goud_physics_destroy()
  • goud_physics_set_gravity()
  • goud_physics_add_rigid_body() / goud_physics_remove_body()

Physics providers are registered globally per context ID.