I am using PathUtilities.IsPathPossible
before setting the destination of my wandering AI, but they are still picking position that are not reachable (blue circle gizmos):
Im I doing something wrong?
Generating a random point in a radius:
public Vector3 GenerateRandomPoint()
{
Vector2 point = Random.insideUnitCircle * radius;
Vector3 dest = new Vector3(point.x, 0, point.y) + transform.position;
return dest;
}
Checking if point is reachable:
public bool IsPathPossible(Vector3 destination)
{
GraphNode node1 = AstarPath.active.GetNearest(unit.transform.position, NNConstraint.Default).node;
GraphNode node2 = AstarPath.active.GetNearest(destination, NNConstraint.Default).node;
return PathUtilities.IsPathPossible(node1, node2);
}
public void Enter()
{
var point = area.GenerateRandomPoint();
if (!IsPathPossible(point))
Debug.Log(unit.gameObject.name + " just set an unwalkable path");
else
SetDesitnation(point);
}
In the above code, IsPathPossible
never returns false.