Writing · The Archive
Ghosts: replaying how earlier visitors walked my island
When the island is quiet, earlier visitors walk it again. The first version looked like robots on rails. Recording the right moments, 8 bytes at a time, and a smooth curve fixed it.
· 4 min read
A multiplayer world has an awkward problem: most of the time, it's empty. You arrive, and you're alone on an island built for a crowd.
So when fewer than three people are online, the island shows ghosts: faint replays of how earlier visitors walked it. Someone strolled to the lighthouse two hours ago, stopped, waved at nobody, and ran to the arcade. You see them do it again.
The first version worked. It just didn't look like a person.
What looked wrong
Watching the replays next to real players, three things gave them away:
- Walking on the spot. A ghost would stop moving but keep its legs going, or glide to a stop without them.
- Robots on rails. Straight lines between points, sharp corners, and the walk animation switching halfway between two samples.
- Popping. Ghosts appeared out of thin air in front of you, and vanished just as suddenly.
All three came down to one design mistake: I recorded on a timer (two samples a second) and replayed with straight lines. A person doesn't move on a timer. The moments that make movement look human, stopping, starting, turning, waving, fall between the ticks.
Record the moments, not the clock
The server already sees every movement update, so it records the trail itself. The new rule:
- keep a sample every time the animation changes (stop, start, run, wave);
- keep one on every turn sharper than 25°;
- otherwise one every 200 ms while they move.
A walk is recorded for its first two minutes and saved only if it's a real walk (at least 10 seconds and 15 metres). It is anonymous by design: positions, facing, animation and which avatar, nothing else. No name, no id. Trails expire after 7 days on their own (a DynamoDB TTL), and anyone can opt out with one checkbox.
8 bytes a sample
Each sample is packed into a fixed binary layout:
dt u16 time since the previous sample, in 10 ms steps
x i16 centimetres
z i16 centimetres
yaw u8 facing, 256 steps per turn
anim u8 idle, walk, run, wave, …
A two-minute walk is under 5 KB. The first byte is a version number, so the old format (7 bytes, in 100 ms steps) still decodes: changing a format should never orphan data that already exists.
Replay a curve, not a line
On the browser side, a ghost's position comes from a cubic Hermite curve through the samples. Each point gets a velocity from its neighbours, so paths bend through corners instead of snapping.
One detail mattered more than the curve itself: where a person stopped, the velocity is zero. Without that, the curve overshoots every stop and drifts back, which reads as "slipping". With it, ghosts ease in and out of stops like people do.
// Zero velocity where they stood, stopped or started: ease in and out, never overshoot.
function velocity(a, b, c) {
if (!a || !c || still(a, b) || still(b, c) || c.t <= a.t) return { x: 0, z: 0 };
return { x: (c.x - a.x) / (c.t - a.t), z: (c.z - a.z) / (c.t - a.t) };
}
Then the animation stops being a recording at all. It's derived from the replayed speed: below 0.25 m/s the ghost stands (and plays its wave or dance, if it made one there), above 2.6 m/s it runs, and in between it walks, with the footsteps timed to the speed. A ghost can't walk on the spot, because walking now means moving.
Entrances and exits
01
Pick a moment
Start where the ghost is 25 m away, or out of your view and 10 m away.
02
Fade in
Over about a second, never popping into view up close.
03
Walk it again
The same path, pace and gestures as the real visitor.
04
Linger, then fade
Stand at the end for a moment, then fade out.
Each ghost also carries a small label, earlier visitor · 2 h ago. It turns a grey figure into someone who was really here.
Testing something you judge by eye
"Looks human" is hard to assert, so the browser test checks the things that broke it. It records a walk with a stop and a wave, then waits alone on the island and samples every ghost ten times a second:
- the recording kept the stop and the wave;
- every ghost appeared at least 10 m away;
- they faded in rather than popping;
- no ghost walked on the spot.
That last check once failed for a single frame. The cause wasn't the ghosts: the test and the playback each ran on their own 100 ms timer, so now and then the test read the same frame twice and saw "no movement". It was a good reminder that a flaky test is often telling you something true about time, just not the thing you were testing.
Ghosts are a small feature. But they're the difference between arriving on an empty island and arriving somewhere people have been.
real-time · architecture · three.js · data