Game Physics skill for Codex

No tunnelling, no jitter, controllers that feel right. Codex turns on debug draw and checks units before touching a single parameter, then picks between an engine's rigid bodies, a kinematic character controller or custom tile collision based on how the game should feel. It fixes tunnelling with CCD or sweeps, declares a collision matrix once, stabilises stacks through mass ratios and sleeping, and treats cross-platform determinism as a design requirement, not an assumption.

  • Game Development
  • $game-physics
  • 146 lines
  • 2 files
  • ~1,800 tokens
  • MIT
  • Updated

Install

curl -fsSL codexskills.dev/install.sh \  | sh -s -- game-physics

Installs to ~/.agents/skills/game-physics/ for every project on this machine.

104-line POSIX script. No sudo, no telemetry. Read install.sh

Use it in Codex

Start a prompt with $game-physics, or pick it from /skills. You can also just describe the task: Codex reads the description below and loads the playbook when your request matches.

What Codex reads before loading it

Implements and debugs game physics - choosing a physics engine (Box2D v3, Rapier, Jolt, PhysX, Havok, Matter.js) or custom AABB collision, broad and narrow phase, continuous collision detection against tunnelling, collision layers and masks, kinematic character controllers, stable stacking, fixed-step integration and cross-platform determinism. Use when objects pass through walls, jitter at rest, explode on contact, characters stick to slopes or walls, physics differs between machines, or when writing collision detection for a platformer or top-down game from scratch.

Use it when

  • Objects tunnel through walls or jitter while resting
  • Building collision for a platformer or top-down game
  • Choosing a physics engine or character controller approach
  • Physics results differ between machines in a networked game

Use something else when

How to check the result

With debug draw on, colliders match the art, 100 shots at the thinnest wall all stop, a 10-box stack rests for a minute, and replayed inputs give matching position hashes.

The mistake it prevents

Building the world in pixel units, so a physics engine tuned for metres treats every crate like a building-sized object that falls in slow motion and jitters.

~/.agents/skills/game-physics/SKILL.md

--- name: game-physics description: Implements and debugs game physics - choosing a physics engine (Box2D v3, Rapier, Jolt, PhysX, Havok, Matter.js) or custom AABB collision, broad and… license: MIT ---

Done well means: physics steps at a fixed rate, bodies use the simplest shape that plays right, fast movers cannot tunnel, collision filtering is declared in one table, characters use a controller designed for game feel rather than a pushed rigid body, and the result is the same on every machine that needs it to be.

Before changing anything

  1. Read AGENTS.md; identify the physics in use (engine built-in, library version, or custom).
  2. Find the step: what rate, fixed or variable, how many substeps or solver iterations.
  3. Check units. Most engines are tuned for metres, kilograms and seconds with objects 0.1-10 m. A world built in pixels (64 px = 1 tile) must be scaled into metres for Box2D, Rapier, Matter-like tuning, or bodies behave like giant slow objects.
  4. Turn on the debug draw before touching parameters. Most “physics bugs” are shapes that do not match the art.

Choosing physics

NeedChoice
Platformer, top-down, tile-based movement with tight feelCustom AABB vs tilemap or a kinematic character controller; no rigid bodies for the player
2D rigid bodies (stacking, ragdolls, joints)Box2D v3 (C), Rapier2D (Rust/WASM JS), engine built-in
3D rigid bodiesEngine built-in: Unity PhysX, Unreal Chaos, Godot Jolt (built in from 4.4; check which engine the project selects) or GodotPhysics; Rapier3D or Jolt standalone
Browser 2D with simple needsPhaser Arcade (AABB), Matter.js for rotation and joints
Browser 3DHavok (Babylon), Rapier (WASM), cannon-es for light needs
Cross-platform determinism (lockstep, rollback)Rapier with enhanced-determinism feature, or custom fixed-point; never assume the engine is deterministic across platforms

Collision pipeline

  1. Broad phase prunes pairs: uniform grid or spatial hash for similar-size objects, dynamic AABB tree (what engines use) for mixed sizes, sweep-and-prune for mostly 1D spread.
  2. Narrow phase tests actual shapes: AABB, circle, capsule, convex polygon (SAT or GJK).
  3. Resolution: compute contact normal and penetration, separate along the minimum translation vector, then resolve velocity along the normal.

Custom AABB vs tiles, resolved one axis at a time (the platformer standard):

function moveAndCollide(body: Body, dt: number, solid: (tx: number, ty: number) => boolean) {
  body.x += body.vx * dt;
  for (const t of tilesOverlapping(body)) {
    if (!solid(t.x, t.y)) continue;
    if (body.vx > 0) body.x = t.x * TILE - body.w;
    else if (body.vx < 0) body.x = (t.x + 1) * TILE;
    body.vx = 0;
  }
  body.y += body.vy * dt;
  body.grounded = false;
  for (const t of tilesOverlapping(body)) {
    if (!solid(t.x, t.y)) continue;
    if (body.vy > 0) { body.y = t.y * TILE - body.h; body.grounded = true; }
    else if (body.vy < 0) body.y = (t.y + 1) * TILE;
    body.vy = 0;
  }
}

Resolving X then Y separately avoids the corner-snagging that happens when resolving both axes from one penetration vector. Cap per-tick movement below one tile size, or sweep in substeps, so a fast body cannot skip a tile.

Tunnelling

A body moving more than its own thickness per step can pass through thin walls.

FixUse when
Enable CCD on the fast body (Unity CollisionDetectionMode.ContinuousDynamic, Box2D isBullet, Rapier ccd_enabled, Godot continuous_cd)Bullets, fast balls; costs per body
Raycast / shape cast along the motion for projectilesHitscan or very fast projectiles; cheaper than CCD
Thicker static collidersLevel geometry, always good practice
Smaller fixed step or substepsWhole simulation unstable; costs everything

Layers and masks

Declare the matrix once, as a table in code or the engine’s project settings, and name layers:

LayerCollides with
WorldPlayer, Enemy, PlayerProjectile, EnemyProjectile
PlayerWorld, Enemy, EnemyProjectile, Pickup (trigger)
EnemyWorld, Player, PlayerProjectile
PlayerProjectileWorld, Enemy
EnemyProjectileWorld, Player

Projectiles that do not collide with their own side remove whole categories of bugs and halve pair counts. Triggers/sensors detect overlap without a physical response.

Character controllers

Do not drive a player by applying forces to a dynamic rigid body unless the game is physics-driven (rolling ball, ragdoll party game). Use:

  • Unity: CharacterController or a kinematic Rigidbody with your own sweep (Rigidbody.SweepTest, Physics.CapsuleCast).
  • Godot: CharacterBody2D/3D with move_and_slide(), tune floor_max_angle, floor_snap_length.
  • Unreal: UCharacterMovementComponent.
  • Rapier: KinematicCharacterController (slopes, steps, snap to ground).

Game-feel rules to implement in the controller, not in physics materials: acceleration and deceleration curves, variable jump height (cut upward velocity on release), coyote time, jump buffering, ground snapping on slopes and steps, and zero friction against walls (or wall contacts stop gravity and the player “sticks”).

Stability

SymptomFix
Stacks jitter or creepMore solver iterations (or substeps in Box2D v3), allow bodies to sleep, avoid extreme mass ratios (> 1:10 between touching bodies)
Objects explode apart on spawnSpawned overlapping; spawn in free space or enable over time
Joints stretchMass ratio too high, too large step; increase iterations or substeps
Small objects vibrateShapes too small for the units; scale the world into metres
Bouncing never stopsRestitution near 1 plus solver error; lower restitution, raise sleep thresholds

Mesh colliders on moving bodies are slow and unstable; use convex hulls or compound primitives.

Determinism

  • Same binary, same platform, same inputs, same step order: most engines are deterministic.
  • Across CPUs, compilers or OSes: floating point differs (FMA contraction, -ffast-math, SIMD paths, transcendental functions). Use a library with an explicit cross-platform determinism mode, or fixed-point math in your own simulation.
  • Never step physics with a variable dt; never iterate bodies from an unordered set; seed every RNG.

Verification

  • Debug draw on: every collider matches its art; trigger volumes are where design expects.
  • Fire the fastest projectile at the thinnest wall at max speed 100 times: zero pass-throughs.
  • Stack 10 boxes and leave it 60 seconds: no creep, bodies fall asleep.
  • Run the same input recording twice (and on two machines if determinism is claimed): position hashes match at every 60th tick.
  • Profile physics step time at peak body count against the frame budget.

Hand-off summary

**Physics:** Godot 4 with Jolt, 60 Hz physics ticks, world in metres (1 tile = 0.5 m)
**Changes:** CCD on bullets; layers World/Player/Enemy/PlayerShot/EnemyShot matrix; player on CharacterBody3D with 8-tick coyote time
**Fixed:** crates jittering (mass ratio 1:50 -> 1:5, sleep enabled)
**Checks:** 100/100 bullets stopped by 0.1 m wall; 10-box stack stable 60 s; physics 1.8 ms at 300 bodies

What the zip contains

SKILL.md plus the interface file below. Nothing runs on install.

agents/openai.yamlgenerated from this page

Gives the Codex app a display name, a one-line description and a starter prompt for this skill.

interface:
  display_name: "Game Physics"
  short_description: "No tunnelling, no jitter, controllers that feel right"
  default_prompt: "$game-physics Bullets go straight through thin walls in our game, fix it"

About this skill

Written and maintained by the Codex Skills editors to the same editorial standard as every skill here: a selective description, a real workflow, known pitfalls and a way to verify the work. First published , last updated . MIT licensed. Something wrong or out of date? Tell us.

esc
Just launched

Codex Skills Pro is live

79 premium skills for Codex, each with scripts, references and an evidence report that proves the result.

Bought one by one$882.21
All 79 skills$49
94% off

That's $0.62 a skill, paid once.

Get all 79 for $49Or pick single skills from $4.99 →

Secure checkout by Creem