Been using a* on my first person 3d project, so far it’s been great. I have a question: is there a simple way to check if my agent’s graph can actually reach it’s destination? (for example, I would like my NPCs to act differently if theyr destinatino is ona different floor).
I did try using IsPathPossible but as for now it’s always returns false even when the NPC clearly has direct path towards the target, so I’m probably unfamiliar with something. Here’s an example for what I’ve been trying to do:
var startNode = AstarPath.active.GetNearest(transform.position).node;
var endNode = AstarPath.active.GetNearest(newDestination.transform.position).node;
// Check if a path is possible on the graph
if (PathUtilities.IsPathPossible(startNode, endNode))
{
followerEntity.canMove = true;
}
I’m still struggling to get this right. The debug looks like the nodes are in the correct places (there’s a very clear walkable path between them), but still it returns false 99% of the time (sometime it would start walking and stop in the middle). When I manually drag the object around with my mouse, sometimes the agent will find it, return true, and go to the destination—but these situations are very hard to reproduce, and I can’t find the logic behind it.
I’m wondering if there’s a mismatch between the transform.position and the node I’m turning it into? I’ve tried to add constraints, but it’s still not working. Maybe there’s a specific constraint that I should be using in order to make sure the nodes are indeed positioned correctly on the graph? Right now I’m trying this, but it’s still no go:
public void MoveTowardsDestination(GameObject newDestination)
var constraint = NearestNodeConstraint.Walkable;
constraint.graphMask = GraphMask.FromGraphIndex(0); // For example
var startNode = AstarPath.active.GetNearest(transform.position, constraint).node;
or in your older version
var constraint = NNConstraint.Walkable;
constraint.nnConstraint.graphMask = GraphMask.FromGraphIndex(0); // For example
var startNode = AstarPath.active.GetNearest(transform.position, constraint).node;