I’m using the free version of A* and am trying to find a way to detect if an ai has a complete path to its target. For example target is in the middle of an area closed in by obstacles and the ai has no path to its target is there a way to check if the ai has a complete path or not?
Hi
You can use PathUtilities.IsPathPossible(node1,node2)
Like
var node1 = AstarPath.active.GetNearest(point1).node;
var node2 = AstarPath.active.GetNearest(point2).node;
Debug.Log(PathUtilities.IsPathPossible(node1, node2));
That’s brilliant, thanks for your help!
I do have one other odd problem that I’ve been trying to work out for a while.I’ve drawn a picture of the problem I’m getting; green is ai and it’s path, blue is obstacle and red is target. This is what I would expect and hope to happen yet it isn’t the case. Any ideas/pointers?
Hi
That is a pretty tricky problem since it is impossible for the scripts to know if you really wanted to find a path to the closest point that it can get to (the topmost node was probably a tiny bit closer than the rest) or just to a sort of close point. One option for mitigating this is to move the target point a small distance towards the agent to break ties.
Gotcha, that makes sense. Thanks for the quick response and help.
Sorry to be a pain, one last question. Is there a way to get the distance of a path?
You can get the length of a path using path.GetTotalLength()