Spielerando

Finding the way

Learning paths through this topic

Make the enemy wait at the ledge until the moving platform arrives

A platform glides back and forth over a gap. Enemies either jump too early and drop, or stand there forever. Here is how to compute the exact moment when boarding works, including the case when it is already close enough right now.

Work out the angle for a shot that bounces off a wall to hit a hidden target

Some shots ricochet, and an AI that aims straight at its target would never use that. Here is the mirror trick that gives the aim in one step, plus the checks that stop it from picking a bounce point that is not actually on the wall.

Choose the order to collect several pickups with the shortest total walk

Always going to the nearest coin next seems natural but leaves the last ones far away. Here is how a game computes the best order for a handful of pickups, with the real walking distances through the level, and when to give up and use a rule of thumb.

Enemies on a curved flight path speed up and slow down along the bends

A wave of ships follows a smooth curve, but they rush through some parts and crawl through others, bunching up and spreading out. Here is why moving the curve's own parameter evenly does that, and how to get an even pace with a small lookup table.

Plan a way through spikes that pop out on a timer, waiting where needed

A route that is shortest on the map is deadly when traps cycle on and off. Here is how a path can include waiting, why time has to be part of the search, and which two moments of a step must both be clear.

A unit pushes against a wall forever because nothing tells it that it is stuck

Characters get wedged in corners, jitter on the spot, or circle a waypoint they never quite reach, and the game never notices. Here is a simple way to notice lack of real progress, even when the character keeps moving.

An enemy chases the player across the whole level and never goes home

A guard should chase for a while and then give up, walk back to its post and wait. Done carelessly, it turns around at the edge of its zone, sees the player again and runs back out, forever. Here is the rule that stops that, and which distance to use.

Make an enemy run to cover without crossing the player's line of fire

The enemy picks the closest hiding spot and sprints across open ground to reach it, getting shot on the way. Here is how to rate a hiding spot by what the trip to it costs, and why the check for being seen has to work in both directions.

Make a shooter walk to a spot where it can actually hit the player

The enemy walks right up to the player, or stops at the wall and fires into stone. Here is how to look for the nearest place that is both close enough and in clear view, and why distance in a straight line is the wrong measure for the walk.

Find the spots in a level where the player drops in and can never get out

One-way drops make a level fun, until a pit has no way back up and the player is stuck for good. Here is how to list every such trap in a finished level automatically instead of hoping someone notices, and why checking the exit alone is not enough.

Send a second enemy by another route instead of behind the first

Every enemy takes the same shortest route and arrives in a queue, one at a time. Here is how to make later ones prefer a different way when there is one, and why that must be a price on the shared path and never a ban.

A fleeing enemy runs into a dead end instead of getting away

When a wounded enemy simply steps away from the player, it ends up pinned in a corner a moment later. Here is the trick that lets it pick a far, open escape even if the first steps lead sideways, and the one cell it must never cross.