How to avoid objects/areas dynamically?

I’m using a recast graph in 2D with AIPath. As you can see in the picture, I would like the red agent (AI) to avoid the blue object (e.g. player) “as much as possible” but not like it’s an impassable barrier - if forced in a bad position, it should go through the circle, but still as far from the blue object as possible.

What is the best way to achieve this? From what I can tell area penalties are fixed and static. Local avoidance seems to only consider other agents? Or should I write a custom heuristic / penalty system somewhere?

Btw, is the distance based penalty even possible with navmeshes? If I had to penalize a node it would be one value for the entire node, which wouldn’t make sense since they’re all differently sized.

Hey check out ITraversalProvider
You can assign a custom one for the path.

You can add extra penalty based on distance in GetTraversalCost


Thanks, it should be possible to calculate this custom heuristic score via ITraversalProvider. Will udpate if I encounter any problems.

1 Like

Well, it works, but apparently all modifiers ignore penalties, so the path ends up in a useless zig zag shape.

Any ideas for that?