Paths don't take the direct route

The trace path that gets generated seems like it is curving out of the way instead of taking a direct path. Here is an example:

The path is supposed to be going to the cement block, but instead it curves around it. I’ve tried playing around with a bunch of modifiers and their order, but haven’t found a combination that works.

I have tried it with both ABPaths and Flood/Tracer paths. I also tried playing with a bunch of different parameter in the Recast graph.

Edit : I figured out what is causing it, but I still don’t know how to fix it. I have a navmesh cutter attached to the cement block. If I remove the navmesh cutter from the block, then the path goes straight to it. So apparently something in the navmesh cutter causes paths to the object go all wonky and only enter the navmesh cut from a single side. I will try to find a setting that can fix it.

I spent a couple more hours changing AStarPath settings and navmesh cut settings but couldn’t find one that made a difference. In this pic, the white line shows the path without any modifiers and the yellow one is with modifiers (funnel, smooth, startend, radius, and clamp-to-ground). This tells me that the problem is not with one of the modifiers. The problem is not as drastic in this pic, but the path is going to the side of the destination instead of going straight to it. I have seen other examples where the chosen path takes curves way behind the destination and then loops back 180 degrees.

Coincidentally, 7 hours before I posted this question, @AlManiak posted the same question here: Need help understanding Closest On Node Surface end point snapping . I can tell by the screenshot that he is using a navmesh cutter as well.

I hope this is something fixable because it’s important that my nav agents move towards an item that has a navmesh cut around it without looking like they’re drunk. :crazy_face:

Hi

I think your problem and @AIManiak’s problem is very different (at least in the second screenshot, I can’t see what’s going on in the first screenshot because it has some very heavy smoothing).

Generally, the issue in your second screenshot is that the tiles in your graph are very small, and this causes the path quality to suffer. You can read more about that at the bottom of this page: Using navmeshes - A* Pathfinding Project
The solution is to either increase the tile size of your graph (which I would recommend anyway, it’s just a lot more efficient than having them be this tiny), and/or using funnel simplification. If you use the current released version the RichAI component has a funnel simplification option (but not the funnel modifier or the aipath script). If you use the beta version the funnel modifier also has a simplication option (exposed as a Quality setting, if you set it to ‘High’ then it will simplify the funnel). Take a look at the documentation for it here: FunnelModifier - A* Pathfinding Project

Thanks for helping Aron!

I don’t think the issue is the tile size, and I think that AlManiak and I are having the same issue. I noticed the problem with the default settings for tile and cell size and I only changed them in the second screenshot to better visualize the path. I want to emphasize that without the navmesh cutters, the paths go straight to the destination as one would expect.

Here is a screenshot with the default settings (white is without modifiers and yellow is with modifiers - funnel, smooth, start-end, radius, and clamp-to-ground:

And here is another one:

And here are the settings used in those two screenshots:

It looks to me as if the original path is not going to the correct endpoint so no amount of filtering will help. Perhaps I have an incorrect setting or there is a known issue? Thanks again for your help.

Oooolala I just saw your solution on AlManiak’s question - that looks promising - I’ll give it a shot and report back!

It works!!! Thanks Aron!!

For some of my paths, 0.1 was not enough because it doesn’t take into account the size of the navmesh cut. So I worked out a way to scale based on the navmesh cut size.

To adjust by size, I calculate the “radius” of the navmesh cut. In other words, the max distance of the center of the navmesh cut to the farthest edge - radius for a circle cut, and distance-between-center-point-and-furthest-point for a rectangle (math.dist(float3.zero, cut.rectanglesize.x, cut.rectanglesize.y).

This came out to be 0.04950495049f.

So basically, the new equation is:
destination = cubeCenter + (agent.position - cubeCenter).normalized * radius * 0.04950495049f;
Where radius is the radius of the navmesh as mentioned above.

Works great!

1 Like