Adding intelligence to pathfinding

Hello friends :slight_smile:

One thing I’m wanting my AI to do involve more dynamic concepts. I’m wondering if any of these are possible:

Runtime Surface Costs
The current way for calculating costs of a certain surface is pretty static, by nature. Is there a way to have more of a “dynamic” cost, which allows me to attach more complex calculations depending on the agent? For example, some agents can swim, while others can’t … some agents may have fire resistance, while others do not.

Other examples are things like doors, which may be locked, may be not. If they’re locked, does the agent have a key? If not, maybe the agent is strong enough to smash it open? Same goes for other destructables such as breakable ice walls.

Obviously the nitty gritty is irrelevant, just giving examples.

Portals
Is there a way to define teleporting positions for AI?

Thank you!

1 Like

I don’t think the costs system was built to be dynamic on a per-agent base, unfortunately. Even per agent-type things seem largely static and would have you rely more on using the NavmeshComponents volumes to change costs at runtime (and again, that would be per agent type, so if one “has a key”, all the other agents of the same type do too…)
As for portals, I suppose Unity just wants you to use NavMeshLinks for those…

1 Like

Makes sense. I suppose I’m asking too much for a navigation system.

EDIT: never mind, astar pathfinding project seems to have dynamic post processing and other modifiers, so I guess I’ll look into that :o

How I handled that was implementing a grid based solution for local pathfinding. So then I can tie costs to anything I want easily. I pathfind on the grid, then construct a navmesh path from the grid path. When I build the grid I query the navmesh at each grid cell, so only cells that are valid on the navmesh are valid on the grid.

But I use the job system and burst to get around how memory heavy that approach can be. I build the grid dynamically around agents as they move around, periodically removing cells out of range. Depending on map sizes and how agents are distributed there are other approaches to maintain the grid, that part is going to be fairly game specific as to what is the best approach.

1 Like

Each agent can have it’s on surface cost and you can change cost and surface layer in runtime, no big deal. Look at e.g. NavAgent.SetLayerCost.

https://docs.unity3d.com/530/Documentation/ScriptReference/NavMeshAgent.SetLayerCost.html

Looks like this function has changed to NavMeshAgent.SetAreaCost. This is definitely useful for some things (the swimming example), thank you!