Skip to main content
2 of 2
replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/

I usually find it best to augment A* pathing with other forms of path finding for other localized scenarios; unit avoidance is usually one of them, especially in a world where there are multiple agents moving simultaneously and thus creating dynamic blockers).

Generally, an edge-following technique can work for this. When you are following a path an encounter a blocker that wasn't part of the original path computation, you basically pick a direction (clockwise or counterclockwise) and try to traverse the blocker by travelling around it in that direction. If you can't, you wait for the blocker to resolve itself (although this can result in a deadlock).

You can also implement the ability for units to path co-operatively; that is, a unit can ask another unit to move aside slightly so it can "squeeze past" the blocking unit. This doesn't work well in a tile-based game where you are restricted to tile-based movement, though, because you can still deadlock in single-width corridors like your example. In that case you can provide for the units to ask eachother to "switch places," which results in resolution most of the time. Occasionally this leads to units leapfrogging eachother, though.

"Unit avoidance" is a fairly common topic when discussing pathfinding in games, there are a lot of hits out there for it. In particular you may want to check out this question on the "flow field" pathfinding used in Supreme Commander 2. RTSs usually run into this problem a lot and solve it in all sorts of interesting ways.

user1430