Can I check that a path is possible with tags?


#1

Hi Aron,
I really love to use this asset for our project!

While I am developing a zombie AI,
I want to set a AI’s target as closest possible one.
Currently I am doing it as just closest one by calculating the distance, without checking path is possible.

I looked through the documents but had no luck about any API I need.
I found the ‘IsPathPossible’ method but it works without checking tags.

so, Can I do what I want from existing API or need to implement myself?
I think it’s gonna be really hard to dig down your wonderful source codes though.

Thank you.


#2

Hi

There is an overload of IsPathPossible that tags a tag mask. Note however that the version that takes a tag mask is significantly slower than the one that does not.
See https://arongranberg.com/astar/docs/pathutilities.html#IsPathPossible3

You could also use a MultiTargetPath to get the closest AI I suppose.

// Your AIPath/RichAI/AILerp script
var ai = GetComponent<IAstarAI>();
List<Transform> zombies = ...;

var path = MultiTargetPath.Construct(ai.position, zombies.Select(p => p.position).ToArray(), null, null);
path.pathsForAll = false;
AstarPath.StartPath(path);
path.BlockUntilCalculated();
if (path.error) {
	Debug.LogError(path.error);
} else {
	// Extract the position of the zombie that was closest
	ai.destination = zombies[path.chosenTarget].position;
}