Back Toward the Ship at the First Wall

Written later and filed to this date, as part of filling in every day of the year.

What. My game’s expedition mode has quests, and one of them hands the player a drone to escort. Hostiles are meant to break off from the ship and go for the drone: the melee chasers since the navigation layer arrived, and two ranged types after a later work order gave them an interest in it. In the open they did. The moment a wall came between a chaser and the drone, the chaser turned and walked back at the ship. It still moved plausibly. It moved the wrong way, and from the cockpit the quest read as broken.

When it was noticed. Not in play. A work order widening the drone’s pull to two more enemy types was going through the navigation code to add them, and filed the defect it found on the way as a bug of its own: pre-existing for the nine melee chase types since the navigation layer shipped, and about to be inherited by the two it was adding.

The cause. Enemies route by a flow field, a grid solved once per refresh that says, from any tile, which neighbouring tile is one step closer to the target. The expedition adapter solves it toward the player on every refresh, because the player is what nearly everything hunts. The chase heading has rungs: go straight if there is line of sight, else step along the flow field, else slide along the wall tangent. The AI substituted the drone’s position for the target and tested line of sight against the drone, correctly. When sight was lost it fell to the flow rung, and the flow field had only ever been solved for the ship. A follower behind a wall from the drone took the one step the field offered, which was a step toward the player, and kept taking it.

The fix. Not a second field. Solving another grid every refresh for at most four bodies is the cost the navigation layer exists to avoid, and the commit says so. Instead the per-frame navigation call carries one more fact: whether this enemy’s target is off the flow route. When it is, the heading skips the flow rung and drops straight to the wall tangent, and the tangent is derived from the caller’s own direct vector, which points at the drone. The player’s route leaves the path entirely rather than being outvoted. No component field moved, no save version, and a mode that never sets a decoy route runs byte-identically.

What guards it now. Three tests on the chase heading, each with a fake flow field that always steps one tile toward the ship and no line of sight to anything. A follower whose target is off the route keeps walking at the drone in the open. The same follower with a wall between it and the drone turns along the wall, never back toward the ship. A hostile still chasing the ship keeps the flow route. The comment above them records what the bug had been: the failure is silent, the enemy still moves plausibly, just in the wrong direction.


← all writing