How to make graph scan ignore collider of specific agent?

Hello!
I’m working on a 2D mobile game and I’m starting to implement pathfinding for basic AI.
the system works great, though right now I have specific requirement but I’m not sure if the system already have a solution for it (as I’m a beginner)

in the map of my game, there are numbers of obstacles,
Astar graph scans and show walkable/unwalkable nodes as expected :smile:

I also have number of “agents” that would move around, each of which has their own collider and can block one another.
Astar graph scans and show walkable/unwalkable nodes on those agents as well.

lets look at this case:

  • we have 3 agents: A, B, C
  • I want agent A to go to B’s location
  • I call Astar graph scan
  • result show that nodes near A, B, C are not walkable
  • A moves around its own location to reach B
    => what I want is the graph should show nodes near A as walkable (for A agent itself)
    (nodes near B, C are not walkable for A, that’s ok)

my solution:

  • after Astar graph scan: mark nodes near A as walkable
  • call “seeker” to find path
  • proceed to move A to its destination

my solution #2:

  • disable A’s collider
  • call Astar graph scan
  • call “seeker” to find path
  • proceed to move A to its destination

=> is this alright?
is there other solution for this?

Thank you for reading.

Hi

You might be interested in this page: https://arongranberg.com/astar/docs/turnbased.html

1 Like

Hi aron,
thank you for the link, now I can make agent avoid others except itself.

but I encountered another problem:
I use “Traversal Provider” for path scanning (as in turnbased sample)
if I set the destination inside other agent (my agent could cover several nodes), the path search would fail due to the node closest to the end point could not be traversed

with path scan without “Traversal Provider”, if I put the destination inside obstacle, the agent would stop at a walkable node near the destination

how do I make the scan with “Traversal Provider” return a path to nearest walkable node instead of an error?
I tried to set nnConstraint, both Default and None, but that didn’t work.

Thank you for reading.

Yeah, that API is not optimal at the moment because it was designed before the ITraversalProvider existed, so the NNConstrainted (used for finding the closest node to a point) does not take the ITraversalProvider into account. You can solve this by providing a custom NNConstraint (path.nnConstraint)

Something like

class MyNNConstraint : PathNNConstraint {
    ITraversalProvider traversalProvider = ...;
   Path path;
   public override bool Suitable(GraphNode node) {
        return traversalProvider.CanTraverse(path, node) && base.Suitable(node);
    }
}
1 Like