30 · AI · 2D and 3D

A* pathfinding

How enemies chase you around walls instead of into them.

Moving straight at the player works until the first wall. A* explores outward from the start, always trying the step that looks cheapest so far plus a guess of the distance left, and finds the shortest route without searching the whole map. The guess is what makes it much faster than a blind search.

WASD or arrows runP show pathC add a straight-line chaserR resetUse the d-pad to run; tap tiles to add or remove walls

Try this: Run around the walls: the red slime uses A* and follows you round corners. Turn on the straight-line chaser (C): the grey one walks into the first wall and gets stuck. Click tiles to build walls, or wall yourself in to see the slime give up.

exploredA* pathwall

Survived 0.0 sCaught 0Tiles explored 0

Run! The slime re-plans its route every 0.25 s.

Prompt bit

Works for 2D or 3D in any engine (Unity, Unreal, Godot, web). Paste the short one for a quick fix, or the detailed one when you want it done properly.

Add A* pathfinding on a walkable grid: expand the open tile with the lowest cost-so-far plus Manhattan estimate, recompute a path at most every 0.5 s rather than every frame, and return the closest reachable tile when the goal is blocked instead of freezing.

44 words · one sentence to paste as is

Where it's used

Common mistakes

Re-pathing every frame for every enemy, an estimate that overestimates (paths stop being shortest), searching forever when the goal is walled off, and letting diagonal moves cut through wall corners.

Writing this with an AI assistant? See our best AI coding assistants for game developers.

Missing a concept? Request one.

Related concepts

New concepts, in your inbox.

One short email when we add new concepts, plus our weekly roundup of AI tools for game devs. Unsubscribe any time.