GridGraph pathfinding goes over blocked over areas. How to improve?

I’m currently working on a grid graph setup with illegal areas blocked by colliders and configured using the grid graph collision testing settings. It works, but the paths produced are of low quality and still go over illegal areas (albeit tangentially). How can I improve this?

My agents use a custom AI based off of RVOExampleAgent and move using RVOController.Move().

You can see in the attached image that the gizmos which trace the nodes in the path hit the illegal areas.

Hi

Could you draw the whole path? I can only see the part they are moving to right now (which I assume is the blue gizmos).

Hello, thanks for the speedy reply! Here’s the new screenshot. As you can see, the A* does its thing and doesn’t include the illegal nodes. But the straight line between path nodes still goes through illegal territory. Is there any way to improve this?

Hi

I am not sure what modifiers you are using to modify the path after it has been calculated.

Hello there, as far as I know, I’m not using any modifiers. Like I said, I just based this off of one of the example classes.

Here are some code snippets:

List<Vector3> vectorPath;
Seeker seeker;
private float nextRepath = 0;
private Vector3 target;
private int waypointIndex;

public void RecalculatePath()
{
    nextRepath = Time.time + repathRate * (UnityEngine.Random.value + 0.5f);
    seeker.StartPath(this.transform.position, target, OnPathComplete);
    this.target.y = this.transform.position.y;
}

public void OnPathComplete(Path _p)
{
    ABPath p = _p as ABPath;

    if (this.path != null) path.Release(this);
    this.path = p;
    p.Claim(this);

    if (p.error)
    {
        waypointIndex = 0;
        vectorPath = null;
        OnMovementComplete();
        return;
    }

    Vector3 startPos = p.originalStartPoint;
    Vector3 characterPosition = transform.position;
    startPos.y = characterPosition.y;
    float startToCharacterPos = (characterPosition - startPos).magnitude;
    waypointIndex = 0;

    this.vectorPath = p.vectorPath;
    Vector3 waypoint;

    for (float t = 0; t <= startToCharacterPos; t += moveNextDist * 0.6f)
    {
        waypointIndex--;
        Vector3 pos = startPos + (characterPosition - startPos) * t;

        do
        {
            waypointIndex++;
            waypoint = vectorPath[waypointIndex];
            waypoint.y = pos.y;
        } while ((pos - waypoint).sqrMagnitude < moveNextDist * moveNextDist && waypointIndex != vectorPath.Count - 1);
    }
}

Ok, maybe you want to reduce the moveNextDist then?

No, the purpose of that is just to find the nearest waypoint in the path from the character when the seeker completes pathfinding so the path traversal starts there. It doesn’t affect the path at all.

Hi

Could you point out which lines you mean. The blue ones? And if so, how are they calculated?

Hello. Thanks for taking the time to sit this through.

This is how I call seeker.StartPath();

private Vector3 target;
seeker.StartPath(this.transform.position, target, OnPathComplete);

And here is how I retrieve List<Vector3> vectorPath; which defines the blue lines and gizmos you see in the screenshot.

ABPath p = _p as ABPath;
if (this.path != null) path.Release(this);
this.path = p;    
p.Claim(this);
if (p.error)
{
    waypointIndex = 0;
    vectorPath = null;
    OnMovementComplete();
    return;
}
this.vectorPath = p.vectorPath;

Like I said, everything seems to be working perfectly, it’s just that maybe the nodes are too far apart to be able to walk around illegal nodes. Is there maybe a way so that the returned vectorPath from the ABPath has a shorter distance between nodes? It appears to me that it “skips” nodes to cover a certain distance.

Hi

I would advise you to look at your GameObject and see if you see any components which have “Modifier” in the name.

1 Like

Oh, I see it now! I have a SimpleSmoothModifier attached. I didn’t know it worked that way. Thank you very much! That solved the problem! :smiley: