Search Unity

Agent will pass through nav mesh obstacle in mass numbers

Discussion in 'Navigation' started by OldKing_Wang, Feb 25, 2020.

  1. OldKing_Wang

    OldKing_Wang

    Joined:
    Jan 25, 2015
    Posts:
    46


    Hi guys

    i have an issue with the nav system. hope can get some help here :)

    i am building an RTS game right now . and you can check the video i attached at top.

    i want use a NavMeshObstacle to block the path but not crave it . so that the agent will still follow the old path.

    when the agent num lower than 100 , every things works great. but if i increase the number to 200 or 300.

    the agent start to pass through the obstacle.

    how can i fix it ?

    thanks.

    Jietu20200226-003742.jpg


    Jietu20200226-002110.jpg
     
  2. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    It seems that every agent in your group has the exact same target position which leads to the behaviour you see. The more agent try to get to the same location the more likely it gets that they push each other through the obstacle.
    Avoidance alone cannot handle this situation.

    When you start moving a group of agents, you should instead give each agent a different offset position to the target, depending on their start position.
     
  3. OldKing_Wang

    OldKing_Wang

    Joined:
    Jan 25, 2015
    Posts:
    46
    hi thanks for reply.

    but i think even i gave each agent different destination when they pass a narrow space with obstacle block the entire gap. (like my prior video) will still have the same issue.
     
  4. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    I am really puzzled by your answer. Did you try it, or do you just think it doesn't work?
     
  5. OldKing_Wang

    OldKing_Wang

    Joined:
    Jan 25, 2015
    Posts:
    46
    apology, when i said it, i haven't run any test.

    anyway i try for random destination. the result is same :(

    video:



    code:

    Code (CSharp):
    1.  
    2. husing Sirenix.OdinInspector;
    3. using UnityEngine;
    4. using UnityEngine.AI;
    5.  
    6. public class TestO : MonoBehaviour
    7. {
    8.     public GameObject Prefab;
    9.  
    10.     public Transform aimTrans;
    11.  
    12.     public Transform bornTrans;
    13.  
    14.     public int num;
    15.  
    16.     [Button("Run", ButtonSizes.Large)]
    17.     private void Run()
    18.     {
    19.         var bornPos = bornTrans.position;
    20.         var aimPos = aimTrans.position;
    21.         for (var i = 0; i < num; i++)
    22.         {
    23.             var rPos = new Vector3(aimPos.x + Random.Range(-20f, 20f), aimPos.y, aimPos.z + Random.Range(-20f, 20f));
    24.             var agent = Instantiate(Prefab, bornPos, Quaternion.identity).GetComponent<NavMeshAgent>();
    25.             agent.SetDestination(rPos);
    26.         }
    27.     }
    28. }
     
  6. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    Oh I see. I am really wondering why they are still trying to reach the target. But the
    NavMesh
    does not seem to have been altered by the
    NavMeshObstacle
    , if I read your first screenshot correctly.

    Did you set the "Carve" option on your
    NavMeshObstacle
    ?

    What should actually happen is that they get a partial path to your
    NavmeshObstacle
    . They will still push themselves around, because they all get a very similar path end position.

    To solve that is a little more complicated. But you can e.g. select a leader of a group check if it reached it's path. If not then adjust the new target accordingly with the respecting offsets.
     
    Last edited: Feb 26, 2020
  7. OldKing_Wang

    OldKing_Wang

    Joined:
    Jan 25, 2015
    Posts:
    46
    Jietu20200227-153012.jpg Jietu20200227-153048.jpg

    the logic i'm try to achieve is use the "Wall" to block enemy attack. meantime my own soldier can go throw the wall (NavMeshAgent Obstacle Avoidance quality is None).

    so i think i can't use "Carve" property.

    1` if i "Carve" the path, the enemy will repath (not test).
    2` my own solider also can't pass through.

    ====

    i asked Aron Granberg (A* Pathfinding Project) about it (https://forum.arongranberg.com/t/pre-purchase-questions-rvo/8056)

    he said A* Pathfinding Project won't have the issue . i will try his plugin first. if still have the same issue . i think i may need write some logic to prevent it happen.

    anyway thanks for your help.
     
  8. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    A* is more advanced than Unitys Pathfinding system for sure. Afaik the new version also provides really good solution for RTS gameplay. I think you can't go wrong with this.
     
  9. sandiprudani

    sandiprudani

    Joined:
    Aug 16, 2012
    Posts:
    2
    you got the solution for this problem by using A* ?
     
  10. OldKing_Wang

    OldKing_Wang

    Joined:
    Jan 25, 2015
    Posts:
    46
    yep. just ues A* Pathfinding Project Pro(Beta) . and when the actor stop and attack the building then mark it to block

    Code (CSharp):
    1.  
    2. private RichAI mRichAI;
    3. private RVOController mRVO;
    4.  
    5. public void StopAndCleanDestination()
    6.  {
    7.             mNowDestination = Vector3.zero;
    8.             mRichAI.isStopped = true;
    9.             mRichAI.canMove = false;
    10.             if (mRVO)
    11.             {
    12.                 mRVO.locked = true;
    13.             }
    14. }
    15.  
     
    odaimoko likes this.