[Solved] Can't Reached Target

The target is in a position that the AI agent cannot reach due to height restrictions.

Is there a way for the AI agent to determine that the target is out of reach?

I tried the below method and it didn’t work.

GraphNode node1 = AstarPath.active.GetNearest(point1, NNConstraint.Default).node;
GraphNode node2 = AstarPath.active.GetNearest(point2, NNConstraint.Default).node;

if (PathUtilities.IsPathPossible(node1, node2)) {
// Yay, there is a path between those two nodes
}

Hi

Could you show the exact code that you used? The above code should work for your use case.

Used Code

GraphNode myNode = AstarPath.active.GetNearest(transform.position, NNConstraint.Default).node;
GraphNode targetNode = AstarPath.active.GetNearest(destination, NNConstraint.Default).node;

bool result = PathUtilities.IsPathPossible(myNode, targetNode);

return result;

Odd. That should work.
Do you think you could verify that when you set A* Inspector -> Settings -> Graph Coloring to “Areas” then the two regions you are interested in show up in different colors?

Yes.

I’m using “Recast”.
Could this be the cause of the problem?

If they are different colors then the IsPathPossible function should return false. That is literally what it checks for.

Do you think you could verify that the nodes you check are indeed at the right positions?

Debug.DrawRay((Vector3)myNode.position, Vector3.up, Color.magenta);
Debug.DrawRay((Vector3)targetNode.position, Vector3.up, Color.cyan);

Looks reasonable.
But in this case the agent really can reach the target. What if that is not the case?

Good Work!!

But…
Sometimes fail in the same area.

image
This looks very strange.
The cyan line is supposed to be at the center of a node… but it doesn’t look like that at all.
Do you by any chance have multiple graphs in the scene? Are you updating them in some way? Do you have off-mesh links?

Sorry.

use 2 recast graph.

recast graph 0 - walkable Height 2
recast graph 1 - walkable Hieght 4 (this use graph)

Hi

Ah. So when you call GetNearest it will find the closest node on any graph.
You will want to specify which graph to use.
I assume you have configured the Seeker component with which graph is valid for each agent.

var nn = NNConstraint.Default;
nn.graphMask = seeker.graphMask;
var ... = AstarPath.active.GetNearest(somePoint, nn);

Thank you.

It’s working very well.

1 Like