Search Unity

Adding intelligence to pathfinding

Discussion in 'Navigation' started by joshcamas, Apr 24, 2019.

  1. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    883
    Hello friends :)

    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!
     
    Last edited: Apr 24, 2019
    JBR-games likes this.
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    382
    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...
     
    joshcamas likes this.
  3. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    883
    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 :eek:
     
  4. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,479
    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.
     
    joshcamas likes this.
  5. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    164
    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
     
  6. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    883