Can't stop AI from walking over barrels

Using the recast graph, I can’t stop the AI from walking up and over the edges barrels rather than around them. This does not happen when using a layered grid graph.

You can see from the screenshot barrels are excluded from the graph, so the AI should walk around them. However, they end up clipping the barrels as described

For both the recast and layered grid graph, I add this code:

Pathfinding.RaycastModifier raycastModifier = workingObject.AddComponent<Pathfinding.RaycastModifier>();
 		raycastModifier.raycastOffset = new Vector3(0, walkableCharacter.GetBodyHeight * .5f, 0);
 		raycastModifier.mask = LayerManager.aiPathBlockers;
 		raycastModifier.useGraphRaycasting = true;
 		raycastModifier.useRaycasting = true;
 		raycastModifier.thickRaycast = false;
 		raycastModifier.quality = RaycastModifier.Quality.Low;

For the raycast graph only, I add this code:

SimpleSmoothModifier simpleSmoothModifier =
                    gameObject.AddComponent<SimpleSmoothModifier>();
                    simpleSmoothModifier.iterations = 1;

The reason I add simple smooth modifier is otherwise all AI in the scene that start near each other take the same path rather than walk directly towards the target. Layered grid graph doesn’t have this same problem, so I leave it off.

How do I use recast graph, where all the units with a close proximity destination and origin take a direct path, but also do not clip and walk over barrels?

Hi

I do not recommend a simple smooth modifier for the recast graph. I recommend that you only use the funnel modifier for the recast graph and no other modifiers.
The simple smooth modifier may (if you are not careful with the settings) cause the path to clip into obstacles.

I’m not quite sure what you mean by “take the same path rather than walk directly towards the target” though.

1 Like

With the funnel modifier the problem is even worse

FunnelModifier funnelModifier = Utility_Common.CreateOrGetComponent(gameObject, out isNew);
funnelModifier.quality = FunnelModifier.FunnelQuality.Medium;
funnelModifier.splitAtEveryPortal = false;

They start out in a line, as displayed

After walking forward a few steps, they bunch up
image

A few more steps, they walk to the left side of a rock (so that’s good)
You can see the path is supposed to take them to the left of the red barrel.

The path cuts too close to the barrel, and they end up walking over it, as per my original problem description

Hi

It looks like you may need to increase the resolution of your graph slightly (i.e. decrease the cell size) and then possibly inncrease the ‘character radius’ setting on the recast graph a bit.

I say this because it looks like the margin from the navmesh to the edge of the barrel is very inconsistent which is typically what happens if the resolution of graph is too low.
(See https://arongranberg.com/astar/docs/recastgraph.html#cellSize)