A* Pathfinding Project

Multiple points closest target path (Lazy Pathing)


#1

Update: I’m testing FloodPath right now, looks very promising, and I don’t know how it escaped my attention. Maybe it would be worth mentioning it on MultiTargetPath docs somewhere?

Hi,

I’m trying to make my AIPath/Movement Script visit 3 mandatory positions, sometimes in a predefined order, sometimes following the shortest path. By shortest path I mean calculating the closest target each time it arrives at a waypoint, without knowing the entire path ahead of time (Lazy). What I am doing is, on Start and on arrival, I change the target of the seeker by using a MultiTargetPath.

I don’t really like the MultiTargetPath API all that much, as it makes me use a lot of special cases, delegates and asyncs. In the meantime,

  • I have to create a delegate to receive the MultiTargetPath result, when all paths are calculated.
  • I also need to have a delegate array so I can receive the individual paths as they are calculated, just so my agents don’t sit idle for the duration of the math.
  • Need to sort the vectorPath by path length on response.
  • I have to do that manually every time the graph is changed (which will happen rarely, once or twice every minute).

This code is much more complex than I’d honestly like, and that makes me wonder if there isn’t a pattern any of you might have thought of that solves this kind of problem.

My code is basically:

private void Start () {
    UpdatePaths ();
}

//Called whenever the graph changes,
//    waypoints never change during the lifetime of a "movable" gameObject
public void UpdatePaths () {
    MultiTargetPath.Construct (
        start,
        waypoints,
        dontStandStillDelegates,
        ClosestFoundDelegate
    );
}


public void ClosestFoundDelegate (Path p) {
    //Get reference to Transform with the shortest path
    Transform shortest = t;

    aiDestinationSetter.target = t;
}


public void ArrivedAtWaypoint () {
    if (aiDestinationSetter.target == END) {
        Destroy (gameObject);
    } else {
        //Remove waypoint we just reached
        waypoints.Remove(aiDestinationSetter.target);
        UpdatePaths();
    }
}

Thanks


#2

So, I was reading through the docs, and found FloodPath. It seems like a much much better solution than what I am using right now. Since I have always 3 fixed waypoints, it is probably going to be much better than MultiTargetPath for my use case!

Thanks all!


#3

I’m satisfied with FloodPath, it solved my problem almost perfectly, with just minor changes to my codebase.