Placing a non-traverseable object in path of seeker causes seeker to run into it repeatedly

Hello,

I am noticing that a seeker will not avoid a node tagged as non-traverseable, if it is updated after the seeker has determined its path and is on the way. Seeker, in this case, will just end up walking into the new object repeatedly.

How should I handle this more cleanly? Do I need to recalculate paths for all seekers in motion, when a new object is placed?

Hi

It is hard for the player to know that must recalculate its path.
What you can do is either:

  1. Use a low enough repath rate so that this is not an issue.
  2. Call ai.SearchPath() on all agents when you update the graph (or you can listen for the AstarPath.OnGraphsUpdated callback).

You could also do something fancy like take the steeringTarget property on the movement script and find the closest node to that, then check if that node can be traversed, and if it cannot then you recalculate the path. You will have to be careful for false-positives though if you use some smoothing on the path that may cause it to cut corners a bit.

Something like this:

void Update () {
    if (!ai.pathPending && !AstarPath.active.GetNearest(ai.steeringTarget, NNConstraint.None).node.walkable) {
        ai.SearchPath();
    }
}
1 Like