Find alternative path

Hi,

Here’s my story:
My game is based on tile/turn movement, so the player and enemies move 1 tile per turn. Whenever the player moves, I call Scan() on the enemies (more than 1) to find the path and move them to vectorPath[1] (0 is the current position), the problem is that sometimes two or more enemies return the same path and they can’t occupy the same tile. Is there any way I can use AlternativePath or any other approach to solve this problem?

Thanks!

Waiting for an answer…if possible :smiley:

Sorry. There was another user that PMed me a similar question and I mistakenly though you were the same, so I thought I had already answered you.

You may want to check out the latest beta version (4.0). It has a new example scene called ‘Turnbased’ which shows how to use some utilities that are useful for turn based games. In particular there is a component called ‘SingleNodeBlocker’ which you can use.

What you would do for each tick is something like this:

For each agent
    Plan a path
    path.BlockUntilCalculated()
    Use singleNodeBlocker.BlockAt(nextNodeThatTheAgentWillMoveTo)
    Start moving

This also has the benefit of avoiding to scan the whole graph each tick (which can be slow).

See https://arongranberg.com/astar/documentation/dev_4_0_0_2e59f2b/turnbased.php
See https://arongranberg.com/astar/documentation/dev_4_0_0_2e59f2b/class_single_node_blocker.php

You may also be interested in https://arongranberg.com/2015/06/cooperative-pathfinding-experiments/. I do have a preview version of that, but it is not production ready. You cannot rely on it always being able to avoid collisions.