Creature Physics — From Breathing to Walking

How animals move in Universe · The path from sin() to life

1. Current State

Every creature in Universe animates, but almost none of them move. The distinction matters: animation is a shader uniform feeding sin(uTime); movement is physics — velocity, heading, terrain contact, state transitions. Here is what each animal actually does right now.

Breathing

Universal baseline. sin(uTime * 0.8) * 0.015 scales the body mesh or SDF primitive. Every creature breathes. Nothing else is guaranteed.
all creatures 1 sin() call ~0 cost

Path Following

Lissajous curves for fish and swallows. Elliptical orbits for horses. The path is baked — the creature follows a mathematical curve, never reacting to anything.
fish, swallows, horses sin/cos pairs no awareness

Cave Fish (Most Sophisticated)

Stateful AI with separation avoidance. Fish detect neighbors, maintain minimum distance, freeze when player approaches, resume swimming after a timer. The only creature with a real state machine.
state machine separation player awareness

Horses

3-beat canter kinematics with lofted anatomy. The gait is hardcoded into the horse builder — legs move in a canter pattern, body bobs. But they follow a fixed elliptical path, never touch the ground.
canter gait elliptical path no terrain

Everything Else

Static meshes or simple sin() animation. Sheep sway. Deer stand still. Songbirds perch then fly on a timer. Rabbits hop on a timer. No physics, no awareness, no terrain contact.
static or sin() timer-based no interaction

2. The Physics Library

shared/creature_physics.mjs

The physics library provides the substrate for creature movement. Six systems, composable per-creature.

SystemWhat it doesKey functionCost
Ground following Sample terrainH(x,z) each frame, set creature y to terrain height. Smooth with lerp to avoid popping. followTerrain(pos, terrainH) 1 FBM sample/frame
Velocity locomotion Integrate velocity: pos += vel * dt. Heading from atan2(vel.z, vel.x). Speed clamped per species. integrate(pos, vel, dt) 3 adds + 1 atan2
State machine Finite states: idle, graze, walk, flee. Transitions on timers, proximity triggers, random chance. Each state sets target velocity. updateState(creature, dt) branch + timer
Boids flocking Separation, alignment, cohesion with spatial hashing for O(n) neighbor lookup. Hash grid cell size = separation radius. flock(creatures, grid) O(n) with hash
Catmull-Rom splines Smooth path through control points. Creatures follow spline with velocity proportional to arc length. Looping or one-shot. followSpline(t, points) 4 lerps per eval
2-bone IK Analytic IK solver for legs. Given hip position and foot target, compute knee angle via law of cosines. One acos call. solveIK2(hip, foot, L1, L2) 1 acos + trig

Physics Pipeline

state machine target velocity integrate pos ground follow IK feet gait animation render

3. The Gait Library

shared/creature_gait.mjs

Gaits are sine waves at different phases per leg. That is the entire insight. A walk is four sines 90° apart. A trot is two sines 180° apart. A gallop is four sines with asymmetric timing.

GaitBeatsPhase patternFoot timingBody motion
Walk 4-beat LH, LF, RH, RF — 90° apart sin(phase + i * π/2) Gentle lateral sway
Trot 2-beat diagonal LH+RF, RH+LF — 180° apart sin(phase + i * π) Vertical bob, suspension
Canter 3-beat RH, LH+RF, LF — asymmetric sin(phase + [0, 0.33, 0.33, 0.67] * 2π) Rolling pitch, lead change
Gallop 4-beat rotary RH, LH, RF, LF — rapid sequence sin(phase + [0, 0.15, 0.5, 0.65] * 2π) Deep pitch, full suspension
Hop 2-beat symmetric Both rear, both front — in phase sin(phase), sin(phase + π) Vertical launch, arc

Foot Height Curve

During swing phase, foot height follows a sinusoidal lift: y = liftHeight * sin(π * swingT). During stance phase, foot stays on ground. The swingT fraction (0→1 during swing) drives the entire animation.

Body Synchronization

4. Lithos Decomposition

Every creature physics operation decomposes into Lithos primitives. No new math is needed — the existing glyph table covers everything.

PhysicsPrimitivesOps
Ground following terrainH ⇒ fbm2 (∼) ~40 (FBM)
Heading atan2 → ∼ ≃ ~4
Velocity + position * velocity dt 3
Boids separation - pos_i pos_j → diff, √ diff → dist, · diff / dist ~8 per pair
IK (law of cosines) ≃ (a²+b²-c²)/(2ab) — one cos¹ call ~6
Gait timing ∼(phase × 2π) — sine at different phases 1 per leg
State machine Branch + compare — not math, just control flow ~2
Spatial hash floor(pos / cellSize) — quantize to grid 2

The most expensive operation is ground following (FBM = 6 octaves of noise = ~40 ops). Everything else is trivially cheap. The total per-creature per-frame cost is dominated by terrain sampling.

5. Creature Catalog

Animal Home Moves Follows terrain Has gait Flocks State machine
Bull Taurus Breathes No No No No
Horses Virgo Elliptical path No Canter No No
Sheep Virgo Sway No No No No
Cave fish Cenote Swims N/A N/A Separation Freeze/swim
Rabbit Virgo Hops No Hop No Timer-based
Songbirds Virgo Perch/fly No No No Timer-based
Fish schools Pisces Lissajous N/A Tail wag Pseudo No
Deer Virgo Static No No No No
Swallows Virgo Lissajous flight No No No No

The catalog shows the gap clearly: only cave fish have real behavior. Everything else is on rails or static. The physics and gait libraries exist to close this gap systematically.

6. The Path to Life

Phase A — Now

Breathing + Path Following

Every creature breathes via sin(uTime). Some follow fixed curves (Lissajous, ellipse). No terrain contact, no awareness, no state. Cave fish are the exception — separation + freeze state.
Phase B — Libraries

Ground Following + Locomotion + State Machine

Wire creature_physics.mjs into each creature. Terrain sampling via terrainH. Velocity integration. State machines: idle → graze → walk → flee. Creatures touch the ground and respond to proximity.
Phase C — Integration

IK Foot Placement + Gait Animation

Wire creature_gait.mjs into each quadruped. 2-bone IK places feet on terrain. Gait phase drives leg animation. Body bob and pitch sync to stride. Horses walk, trot, canter. Sheep amble. Deer bound.
Phase D — Emergence

Flocking + Inter-Creature Awareness

Boids for sheep herds and bird flocks. Spatial hashing for efficient neighbor queries. Creatures see each other — horses avoid sheep, birds scatter when player approaches, deer flee as a group.

Integration Pipeline

Phase A sin(uTime) breathe
Phase B state machine velocity terrainH ground contact
Phase C gait phase IK solve foot placement body bob
Phase D spatial hash boids flock velocity emergent herding

7. Connection to ∼

All creature movement is sine. This is not a simplification — it is the literal mathematical content. Every behavior in the creature system reduces to sin() at different frequencies, phases, and amplitudes.

Breathing
sin(t * 0.8) * 0.015 — one sine, one creature, forever
Gait
sin(phase + leg_i * offset) — same sine, different phase per leg. Walk = 4 sines. Trot = 2. Gallop = 4 with asymmetry.
Flocking
Oscillation around flock center — each agent is a damped sine responding to neighbors. The flock IS a superposition of sines.
Ground following
terrainH = fbm(p) = Σ sin(freq_i * p + phase_i) / amp_i — terrain IS sine. Following terrain IS following sine.
Path curves
Lissajous = sin(a*t), sin(b*t). Ellipse = cos(t), sin(t). Every path is a pair of sines.
Body bob
sin(stridePhase * 2π) * amplitude — the body rides a sine wave generated by its own feet
Tail wag
sin(t * wagFreq) * wagAmp — a fish tail is a sine. A dog tail is a sine. Every tail is a sine.

The Lithos glyph is not just a rendering primitive. It is the atom of life. Breathing is sine. Walking is sine. Flocking is sine. The entire creature physics system is a composition of at different scales.