Turn-based system for units to move through others but not occupy the same tile

  • A* version: 4.2.17
  • Unity version: 2022.3.4f1

Hello, I was wondering if this library had a simple / out-of-the-box solution for a turn-based system where units can move through each other but not occupy the same tile? My system is turn-based and using a GridGraph. I’ve used the SingleNodeBlocker component effectively, but that makes units avoid any tile on the path that has a SingleNodeBlocker, whereas I really just want to avoid two units sharing the same tile after their pathfinding is finished (i.e. once their turn is over). I’d also want the units be OK with going through another unit’s final tile for the turn. So I wouldn’t just want to put a SingleNodeBlocker on the final tile either, as that would cause units to go around it.

Hopefully that makes sense. This issue came up because I have a system where AI units take turns figuring out where their goal for the turn will be, but then they all move simultaneously.

I think instead of using SingleNodeBlocker you may just want to reference the tile (independent of Astar) and then check if that tile is occupied? From there you can Astar to pathfind to that unoccupied tile. Under default settings I’m pretty sure they’ll pass right through other units. I may be missing some important context on your situation though.

1 Like

Hey tealxgr, thank you for the suggestion. I ended up basically doing that - for each turn, I keep track of the nodes that are being used as the goal position for any units that are moving on that turn. If any units want to move to an already-taken position, I have a recursive algorithm figure out any possible nearby nodes (possibly closer ones) within moving distance that the unit could still move to.

1 Like

Nicely done! Glad to hear and thanks for sharing that info. Be sure to let us know if you need any more help :+1:

1 Like