Search Unity

Question Make custom obstacles specific to one agent

Discussion in 'Navigation' started by Lutenar, May 29, 2023.

  1. Lutenar

    Lutenar

    Joined:
    Dec 2, 2018
    Posts:
    4
    Hello there!

    I know it's a long shot, and I couldn't come up to a solution yet, so I refer to you gentlepeople!

    Let's say I have a NavmeshSurface with several agents (same type) on it and several dynamic obstacles (doors).
    Doors on the map can be in locked or unlocked state (dynamic carve when agent is close).
    An agent should not have knowledge of a door being locked unless it already has visited it once.
    And here lies my problem. I can't carve the locked door for this moment on, because all other agents will know that this door is locked, albeit at the other end of the map.

    So I need a way to make each agent remember the locked doors they already visited so that they won't make a path through them.

    Not specifically looking for one big complete solution, but if some of you have ideas on the matter, I'm game!

    Cheers
     
    Last edited: May 29, 2023
  2. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    904
    You can use separate NavMeshSurfaces now. Can you use one for each agent who needs to know, or is the number of agents and/or world size prohibitively high for that?
     
  3. Lutenar

    Lutenar

    Joined:
    Dec 2, 2018
    Posts:
    4
    Hey thanks for the answer!
    I thought of using separate surfaces, but didn't try it. I might have up to something like 100 agents, so that many surfaces didn't feel ok.
    Also, obstacles, links etc seem to be surface agnostic, but I may be wrong?

    But! I figured something out. Maybe not the best solution but it works:

    Doorways carve the navmesh surface, and I use offmesh links so agents can traverse the doorways.
    You can change area type of Offmesh links without baking, so I use a temporary change of the area of the links of the doors visited by this agent, change the areamask of the agent to exclude this temporary area, then calculate a new path, which take into account the locked doors.
    I then force the agent to follow this specific path until destination or new locked door.

    Now I have to do something about the weird movements of agents along links. They seem to teleport to the link's starting point when close to it and I couldn't find out how to solve this yet.
     
    Claytonious likes this.