Split The code is public; the app answers only to the crew.

The body stays where it falls: a corpse until the round ends, and a camera that is not inside it #32

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A dead player now leaves a body where they fell, and the camera no longer sits inside the mesh it is looking out of. What changed src/client/bodies.ts is the new concept.

Notes

shipped merged

opened this

A dead player now leaves a body where they fell, and the camera no longer sits inside the mesh it is looking out of.

What changed

  • src/client/bodies.ts is the new concept. A Corpse is four numbers copied out of the player at the moment of the kill — id, team, feet, yaw — plus the time; addBody drops it to the floor under them with groundUnder, so someone shot mid-jump lands instead of hanging. The list is world.bodies, cleared by startRound, capped at twenty, and deliberately not world.effects, which is trimmed to the last two seconds.
  • onKill adds one; so does the bomb going off, which used to erase ten people at once. Nothing is allocated in update for a tick where nobody dies, and arena.reset clears the list next to the pickups so training carries no dead between episodes.
  • The renderer draws each body with the player mesh already on the GPU: one indexed draw, no new mesh, texture layer or program. fallenMatrix in math.ts tips it onto its face about the model's own Y axis so it lies along the way it was facing, flattened a little and lifted onto the floor; it topples over 0.4 s from exactly where the living mesh stood, so a kill reads as a fall rather than a pop.
  • The mesh the renderer skips is now the player the camera is inside (view), not world.me. Spectating a teammate no longer puts the camera inside their head, and the gun in the corner is theirs while you watch them.
  • A body is decoration: traceBullet is untouched, move still collides only with world.boxes, bots never see one.

Frame time. There is no GPU in this sandbox, so what I could measure is the CPU side: one frame of the scene loop against a no-op WebGL2 context costs 8–14 µs, and ten bodies add 2–6 µs of that (three runs, 4000 frames each) — under 0.04 % of a 16.7 ms budget. The GPU side is ten more draws of the 84-triangle player mesh with one matrix and one tint each; renderer.test.ts asserts that ten bodies are exactly ten more drawElements and zero buffer or texture uploads. The honest 60 fps check is the preview's own counter in the corner of the view, with a round played out to ten corpses.

Tests. bun test is green, 202 passing. bodies.test.ts covers a kill adding one, startRound clearing them, the bound holding over 400 kills, the drop to the floor, and that nothing collides with a body or shoots it; renderer.test.ts runs a frame against a recording context (the same trick hud.test.ts already uses) and fails if the skip goes back to world.me; math.test.ts pins the fallen transform. No dependencies added.

What I left out. Bodies are not on the radar and not in the kill feed's geometry, a body is not searchable or lootable, and it does not sink through a floor that moves — the map has none. The pose is one topple, not a ragdoll: the mesh is seven boxes and per-limb physics would be a second simulation for a decoration.

🤖 Generated with Claude Code

Closes #28

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs