Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Stuck zones for NavMeshAgent and Obstacles

Discussion in 'Navigation' started by chanfort, Mar 22, 2015.

  1. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    I noticed that there are dead-stuck zones near static obstacles, when units getting stuck in situations like shown in the image bellow:
    ObstacleStuck.png
    What could be ways to avoid this problem?
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You may try to find out when an agent is stuck and move it into another direction for a certain amount of time. When an agent is stuck, you may wait for a certain random duration until it starts to move into another direction and then move into that direction for a certain (random) amount of time, trying to get rid of that situation.
     
  3. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    How is easiest way to detect when agent is stuck?
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    To make the movement as natural as possible, try to imagine what you would do. That naturally leads to the described reaction and you can also find out when the reaction should take place. You are stuck when you have a target that isn't reached yet, but you barely moved within a certain amount of time.
     
  5. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    well, I implemented the way, that it checks current velocity. If velocity is bellow critical threshold, count how many times it appears. If counter hits critical number of counts, assign random temporary target.

    The most natural way could be probably to recalculate paths at each point, where is risk of collisions (i.e. adding random delay, or changing one of paths to pass around collision point). This is how in real life it happens - when we see things in the front, we changing our walking direction to avoid colliding with objects. However, to implement such approach would probably need to add avoidance carvings for one agent, while allow to pass the other straight through the point. Do I miss something here?
     
  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Usually, it should be possible to rely on Unity's own obstacle avoidance which already should do this pretty much. Only in very special cases where the agent still get suck, a reaction is needed and in those cases it appears most natural to move backwards in order to free the path for other agents. If you use a random time until this strategy is used, it is very likely that only one agent will use it.