A time-trial footrace in Godot: six gates, three medals and a bot that runs it with physics
The relay race: six gates across the western meadow, a 65-second limit and gold at 38. A physics-driven autopilot finishes it in 40.73 s.

Next to Brumacosta stands a turquoise sign: CARRERA DE LAS POSTAS (the relay race). Talk to it and it puts you on the start line, counts down three seconds and shouts "¡YA!" (go!). Across the western meadow there are six wooden gates with pennants, linked by a dirt trail, and a golden ring marks the next one. You have 65 seconds. Gold is at 38, silver at 49, and just finishing earns bronze. Your best time is saved.
It's a race on foot: pull out the broom and the attempt is cancelled. Lía's speed infusions are allowed, and the clock stops if you open a menu. In the screenshot the race has just started: the ring glows on gate 1, the finish arch (META) is behind you and Brumacosta's windmill peeks in on the right.
How it's built
The interesting part is deciding when you've passed a gate. The simple approach is checking whether the player is within 3.2 m of it on a given frame. But when you're running, you could sweep past between two frames without any frame catching you inside. So the race remembers where you were on the previous frame and checks the segment between the two positions:
var target: Vector3 = gates[checkpoint].global_position
var closest := Geometry3D.get_closest_point_to_segment(target, _previous, p)
# The segment can't skip half the circuit: this also guards against teleports.
if p.distance_to(_previous) <= 12.0 and closest.distance_to(target) < CHECK_RADIUS and p.y - Island.height_at(p.x, p.z) < 2.0:
Three conditions:
- the segment passes within 3.2 m of the gate's centre;
- the segment is 12 m long at most, so a teleport doesn't count as running half the course;
- you're less than 2 m above the ground, so flying over it or a huge jump doesn't count.
On top of that, only the current gate counts: crossing another one out of order does nothing. Moving more than 4 m away during the countdown is a false start. When a save loads, the record is clamped between 0 and 65 s, and one test deliberately loads a record stored as a string to check it doesn't break anything.
What went wrong
- The tests weren't modular. To check that "flying cancels the attempt", the race test used the real broom. Remove the broom's folder and the game still worked, but
tests/run.shfailed. Now the test puts the player on a fake mover that just keeps them hovering, so the test no longer needs the broom: all the race cares about is whether the player is riding something. - Checking just the gates isn't enough. It's the same lesson the village taught me when its first location ended up half underwater: the procedural coast has inlets. So the race test samples the whole course, 21 points between each pair of gates, all on land and with a slope under 0.25.
Still unverified
A test drives the character with real physics through all six gates, with no teleports or bonuses, always heading straight for the next one: 40.73 s. In other words, the bot gets silver, less than 3 s off gold. But a bot running in straight lines isn't a player. I don't know whether 38 s for gold is a fair challenge, or how the race feels with the touch joystick. FPS on a phone hasn't been measured either. This screenshot cost 427 draw calls on PC.