How Game Enemies Find You: Pathfinding Explained With a Playable Demo
A guard can know where you are and still get stuck behind a wall. Use our playable maze to see what routing solves—and what needs a different part of the enemy brain.
By Duangduean Studios

Put a wall between a player and an enemy. Give the enemy the player’s exact position and tell it to move straight toward that point. It will happily run into the wall.
Knowing where to go leaves a second job: finding a route you can actually travel. That is where pathfinding comes in. You can explore it in our playable AI Lab, which shows the search spreading across a maze before drawing its chosen route.
Give the enemy a map it can use
A pathfinding system works with a representation of the level. In the demo, that representation is an eight-by-eight grid. Open squares connect to their neighbours above, below, left, and right. Walls remove possible steps. The bot starts in one corner and aims for the opposite corner.
Real games can use different representations, including navigation meshes and networks of waypoints. The shared idea is to describe reachable positions and the connections between them. Red Blob Games has an excellent interactive introduction to how search algorithms work with these connections. Red Blob Games’ pathfinding introduction
Try breaking the route
Open the maze experiment and select Clear walls, then Run search. With four-direction movement, the opposite corner is 14 moves away: seven across and seven down. Several shortest routes are possible.
Next, clear the walls again and block both squares beside the start: row 1, column 2 and row 2, column 1. Run the search. The goal is still sitting in plain sight, but the start has no exit. The demo should report that no route was found.
Remove either of those walls and try once more. You have changed the map’s connectivity with a single square. That is the sort of change a game has to account for when a door closes or a bridge collapses.
Why the blue squares spread out
Our demo uses breadth-first search. It explores positions in order of the number of steps needed to reach them. Every move costs the same here, so the first route it finds to the goal is a shortest one. Blue cells show the exploration. The orange line shows the final route.
If you want to follow the queue and parent links in code, our BFS walkthrough covers that part. The larger development lesson is to choose an algorithm that fits your map. If mud takes longer to cross than pavement, counting steps alone no longer captures travel cost.
A route still needs someone to walk it
Imagine the search returns a path through a doorway. The enemy’s collision body may be too wide for the gap. Or another character might stand in the way after the search finishes. Following the path, avoiding nearby obstacles, and deciding when to search again all need attention.
Detection is another piece. Scroll to the enemy-decision experiment and change visibility, distance, and health. Watch the decision switch between patrol, chase, attack, and retreat. That experiment chooses an intention. The maze experiment solves a route. A convincing enemy needs those pieces to cooperate.
Frequently asked questions
How do game enemies find the player?
Knowing the player's position is not enough, because moving straight towards it runs into walls. Pathfinding searches a map of reachable positions, such as a grid, navigation mesh or waypoints, to find a route the enemy can actually travel.
What is breadth-first search in game AI?
Breadth-first search explores positions in order of how many steps it takes to reach them. When every move costs the same, the first route it finds to the goal is a shortest one.
When is breadth-first search not enough?
When moves cost different amounts, for example when mud takes longer to cross than pavement. Counting steps then no longer captures travel cost, so choose a search algorithm that fits the map.


