Can Seeker Find Path To Target Point Via Intermediate Point?

I have units that attempt to find paths to particular points. If they detect a unit is in their way, they do some basic logic to find a path that avoids that unit – they calculate a relative offset and find a path there first. However, the logic for this is quite cumbersome; I have to juggle when they’ve reached the diversion point, then get a new path to the original target, etc etc.

So what I was wondering – is there some way for me to ask the Seeker for a path that goes to one point via another? Does A* Pathfinding Project provide something like this? If not, could it? :smile:

If there are alternative solutions to making units find paths around each other, I’m all ears; but I’m not using local avoidance as I have my own custom movement logic, and I believe giving every unit a dynamic obstacle would be too costly in terms of performance to be useful in this situation (also would make the units unable to find paths away from themselves as they’d always be off-mesh?).

(I am using GridGraphs if that makes any difference.)

Hi

There is no built-in support for that, however what might work for you is to search for a path where you add a very large cost for moving close to the enemy. I’m not quite sure what kind of scale we are talking about here, but I’m assuming the avoidance of the units would be quite large here (e.g. 10 meters or something in the real world), not just moving past them with a very small margin.

If so you could use the ITraversalProvider to add a penalty for being close to the enemy.

Something like this

public class MyCustomTraversalProvider : ITraversalProvider {
    public Vector3 pointToAvoid;
    public int penalty;
    public float range;

    public bool CanTraverse (Path path, GraphNode node) {
        return DefaultITraversalProvider.CanTraverse(path, node);
    }

    public uint GetTraversalCost (Path path, GraphNode node) {
        var extraPenalty = Vector3.Distance((Vector3)node.position, pointToAvoid) < range ? strength : 0;
        // The traversal cost is the sum of the penalty of the node's tag and the node's penalty
        return path.GetTagPenalty((int)node.Tag) + node.Penalty + extraPenalty;
    }
}

You can then use it like

var path = ABPath.Construct(...);
var provider = new MyCustomTraversalProvider();
provider.pointToAvoid = ...;
provider.range = 10;
provider.penalty = 10000;
path.traversalProvider = provider;
1 Like

O-ho! I’ve had a play around integrating that and it’s exactly what I need – thank you very much! :grinning:

All the avoidance I need is maybe 2-3 units. The units are rigidbodies that can shuffle each other out of the way, so all they need is enough of an avoidance let them push around rather than through, which this does nicely. (In fact it’s even better, as I now don’t even have to worry about directing the unit left or right of the obstacle!)

1 Like