A* Pathfinding Project

Raycast modifier not respecting graph tags?


#1

I’m using the Raycast modifier on my AILerp agent, and it is not respecting tags.

As you can hopefully see in this example, the path is being correctly calculated to avoid the red capsules, but the raycast modifier is pathing straight through them.

I have ‘Use Graph Raycasting’ checked, and ‘Use Physics Raycasting’ blank.

The funnel modifier works perfectly, but is not giving the straight pathing that I prefer when no obstacles or tags are preventing it’s movement.

Any suggestions? Is this a bug?


#2

Up. Same exact problem here. I’m using NavMeshGraph, with various areas marked with different tags.

Funnel modifier alone on NavGraphs can produce very curved paths. Here’s an example of a path that ‘hugs’ edges of the navmesh despite the Grey area having the same zero penalty as the Mahogany zone. That’s a very big deal in my specific use case.

So, I’ve added Raycast and it straightens the paths correctly. Except it doesn’t care about tags and traversability settings at all. Here’s a path that leads straight through a Red zone, which is a lake and which vehicle seeker shouldn’t be able to traverse through.
image

And here a path when the Raycast was removed. Funnel alone respects tags and properly pathes around the untraversable area.
image

So, how to fix this?


#3

Well, looks like a pretty straightforward fix.
What I did was to make Linecasts optionally accept NNConstraint. NavMeshBase was modified to use that constraint in neightbour node check, right where it currently checks walkability:

at around line 1247:
// This might be the next node that we enter
var neighbour = nodeConnections[i].node as TriangleMeshNode;
if (neighbour == null || !neighbour.Walkable || !constraint.Suitable (neighbour)) continue;

That seems to be it? I’m not sure if it covers all cases, but at least that’s the only relevant check I found.

After that, it’s just about sub-classing RaycastModifier into ConstrainedRaycastModifier that accepts NNConstrain and passes it into Linecast calls. Seems to work: no curved lines, no pathing through untraversable terrain. More tests to follow.

P.S. This logic should probably be present in the project itself. It’s weird that Pathfinding respects constraints, while Linecasts completely disregard them and check walkability even if it’s not actually constrained. This is made that much more unintuitive by the modifiers (and probably pathfinding itself?) using Linecasts internally.