Path Distance, AILerp, and Single Node Blockers

Hello! I am working on integrating A* into movement for my 3D turn based strategy game which uses a grid graph. I’m generally there in terms of how I’d like movement to function I just have a few issues.

I am using AILerp for movement as I want it to perfectly follow the path through connections. Looking at the single node blocker tutorial in “Utilities for turn-based games,” I don’t see where movement is ever initiated in either example. How do we configure it such that AILerp will avoid other units?

I worked this out in a way that I am happy with. Essentially just created a second graph; one to handle enemies and one to handle player characters and recast it after movement. Question, though. How do we get the shortest path distance to a targeted square from AILerp?

As I have it at the moment, I assign a target to “AI Destination Setter,” let it walk, and then null the target. What can be done in the middle of this to ensure that pathing is limited to some distance which should be expressed in number of connections taken?

1 Like

Hi

Sorry for the late reply. I’ve been quite sick these last few weeks.
Great that you figured it out.

I think this is best done with a custom path calculation.
Something like:

var path = ABPath.Construct(unit.transform.position, destination);

// Optionally copy settings from a seeker here, like path.nnConstraint.graphMask = seeker.graphMask

// Schedule the path for calculation
AstarPath.StartPath(path);
path.BlockUntilCalculated();

var lengthInNodes = path.path.Count;

This is best done by manually trimming the path after it is calculated. Something like this could work:

var path = ABPath.Construct(unit.transform.position, destination);

// Optionally copy settings from a seeker here, like path.nnConstraint.graphMask = seeker.graphMask

// Schedule the path for calculation
AstarPath.StartPath(path);
path.BlockUntilCalculated();

var maxPathLength = 10;
while(path.path.Count > maxPathLength) {
    path.path.RemoveAt(path.path.Count - 1);
    path.vectorPath.RemoveAt(path.path.Count - 1);
}

// Optionally make the AI follow the path
aiLerp.SetPath(path);