Strange Pathing Issues With NavMeshCuts

Using beta 4.1.5, I’m getting some weird paths on recast graphs near NavMeshCut obstacles. Even worse, they aren’t consistent. Some areas are simply impassible, some require me to go around obstacles that are out of the way and others let my characters through about half the time.

Here are some images of the unusual paths I’m seeing:

Weird trip around an obstacle. Should be able to go straight form start point to finish point.

The red line is impassable (I drew it on in photoshop). Basically, I’m unable to travel between RecastGraphs.

Any idea how to fix this? My characters are using RichAI as a base and have Funnel and Simple Smooth modifiers.

1 Like

This is unfortunately a side effect of how pathfinding on navmeshes work.
Pathfinding is done on the centers of the triangles, and this means that in some cases it is possible that the shortest path in the graph, is not actually the shortest path after it has been simplified by the funnel modifier. For more information, take a look at: https://arongranberg.com/astar/documentation/dev_4_1_6_17dee0ac/getstarted2.php#navmeshnotes
One way to combat this is to do a straight line check before even searching for a path (see RecastGraph.Linecast), and if there are no obstacles, just walk in a straight line. This is not an out of the box option with the current movement scripts, however I think I might add it in the future.
You can also try the RaycastModifier, however that will not necessarily do the straight line check that you want.

Movement between 2 recast graphs is not supported out of the box, usually I recommend against having multiple graphs that your agents move between. Why do you need 2 graphs? Can you do it with just 1?

I think I described it incorrectly. It’s one recastGraph, but the navmesh is displayed as a separate colour. I assume that means it’s two ‘tiles’?

How would I add the initial Linecast to the RichAI script? Not sure which function to put it in.

Hi

Ah. So that is unfortunately a slightly buggy compromise I have had to make for performance reasons.
Why this happens is that it seems your navmesh cut only intersects the purple triangles and not the blue/cyan colored ones. This means that only the purple ones will be cut, but then when it tries to connect the nodes to neighbouring nodes the edges do not line up and no connection is formed.
Is it possible for you to move the cut upwards so that you can guarantee it cuts both of them?

That makes perfect sense. I can increase the height of the obstacles. Thanks!

In regards to the straight line test being added to the RichAI script, could you tell me which function you would put the linecast check in?

I would put it in the AIBase.SearchPath method (RichAI inherits from that class).
Instead of

seeker.StartPath(start, end);

I would do something like

if (no-obstacles-detected-by-linecast) {
     // Fake a straight path to the target
     ABPath path = ABPath.Construct(start, end);
     path.vectorPath.Add(start);
     path.vectorPath.Add(end);
     path.CompleteState = PathCompleteState.Complete;
     OnPathComplete(path);
} else {
     seeker.StartPath(...);
}

Linecasts on recast graphs have historically been slightly buggy due to floating point errors. I have tried to improve the implementation several times but it has never been perfect (edge cases when for example starting a linecast from the border of the navmesh and stuff like that). However last week I finally managed to write an implementation that I think works really well, I haven’t found any cases where it fails yet (and it uses integer math instead of floating point math, which is a lot more predictable). It is also around 1.4x to 3x faster which is nice. So if you discover that your linecasts are logging warnings sometimes, ignore them for now. The new version will be included in the next update.

Thanks so much, Aaron. Your support is amazing.

1 Like

Thank you for the kind words :slight_smile: