Find if a path is possible

I am using AIPath and a basic wander script. I am setting the destination to random points around the AI agent. The problem occurs when the agent gets to the edge of the map and the random point generator selects a point outside of the border. The agents just then stop moving at the border.

I cant figure out how to stop this. Maybe if I could check to see if the path they are currently on is possible.

Do you use GetPointsAroundPointWorld()? Apparently it generates points that are on the graph only.

Thank you for helping. Does that method return anything? The note looks like it doesnt. I am using this:

ai = GetComponent();

ai.destination = PickRandomPoint(transform, range);

here is the method for random point.
public Vector2 PickRandomPoint(Transform trans, float radius)
{

    var point = Random.insideUnitCircle * radius;
    //point.z = 0;
    while (Vector3.Distance(trans.position, point) < radius*2 / 3)
    {
        
        point = Random.insideUnitCircle * radius;
        //point.z = 0;

    }
    //Debug.Log(point);
    //point.z = 0;
    point = new Vector2(trans.position.x + point.x, trans.position.y + point.y);
    return point;
    //return point as vector2;
    //Vector2 v2_point = new Vector2(point.x, point.y);
    //return v2_point;



}

Here are the 2 methods for the wander script. it works but they get stuck at the borders of the map:

public void Wander(float range)
{

    if (!ai.pathPending && (!ai.hasPath))
    {
        
        var constraint = NNConstraint.None;
        var info = AstarPath.active.GetNearest(PickRandomPointV3(transform.position, range), constraint);
        var node = info.node;
        
        ai.destination = info.position;
       
        animator.SetBool("Walking", true);
        
       
    }
   
    if (ai.reachedDestination)
    {
        var constraint = NNConstraint.None;
        var info = AstarPath.active.GetNearest(PickRandomPointV3(transform.position, range), constraint);
        
        ai.destination = info.position;
       
        animator.SetBool("Walking", true);
        
    }
}

No, but apparently the List<Vector3> previousPoints will be overwritten with the result points data. No idea how effective it is though.

By the way, did you try to use ai.reachedEndOfPath instead of ai.reachedDestination?

What is the vector3 is outside the reach of the end of the path? Will reachEndOfPath still trigger?

reachedEndOfPath will be true when the agent has reached the end of the path it is following. If the path ends at the border of the navmesh then it will become true close to that point.

reachedDestination will only become true if the agent can get close enough.

To fix the issue I moved the border to outside the grid. The agent still get stuck on the red dotted areas though. Ill try the reachedendofpath. thank you for your help.

One more question regarding this: How do I increase the range the agent will stay away from collisions? This should help them not get stuck right?

Assuming you are using the grid graph then you can adjust either the ‘collision testing → diameter’ setting or the ‘erosion iterations’ setting.