Search Unity

NavMeshAgents are pushing eachother

Discussion in 'Navigation' started by RIw, Sep 21, 2015.

  1. RIw

    RIw

    Joined:
    Jan 2, 2015
    Posts:
    90
    Hello!
    I've made a simple AI Script,which is based on a NavMeshAgent,which works perfectly but It has 1 issue.
    When I will create 10 NPC's with my script,and when I will give them 1 Target - a player for example.
    They are pushing eachother but I want them to avoid their "brothers" I tried to do something with localAvoidance Property but It doesn't work for me (I see no difference).
    How can I solve this ?
     
    Jordyz96 likes this.
  2. TomPo

    TomPo

    Joined:
    Nov 30, 2013
    Posts:
    86
    After two years you still can't solve this stupid problem.
    Blame you Unity !!!
    Who figured this out that agents should behave like this at the first place ?!
    No avoidance just pushing ? Give me a break. It's not a crowd behavior.

    Workaround:
    - put some bigger colliders on each agent (with some separate layer)
    - in physics setting set that they collide only each other
    - on trigger enter agent with f.g. lower ID (those build-in priority is only from 0-99) so use your own variable
    - stop agent
    - disable navmeshagent
    - enable navmeshobstacle (in this order)
    - on trigger exit
    - disable navmeshobstacle
    - enable navmeshagent (in this order)
    - continue with moving a navmeshagent

    Still super unnatural when one person is stopping but better this than pushing.

    Other option is make quick temp destination (depends of collision angle)
    onCollisionEnter - save main destination
    set new tem destinations to avoid each other
    onTriggerexit - set back main destinations
     
    Last edited: Dec 11, 2017
  3. SM_AF

    SM_AF

    Joined:
    Aug 1, 2017
    Posts:
    23
    I love Unity! But the navigation system is just terrible. I still can't believe it. It is not updated with the same frequency as/together with physics, which is a major issue in my opinion. I mean I get it, they want to make sure that physics primarily will always run stable (I guess?). But then... why not add the update frequency to the project settings? Stable and full physics interactions with vehicles for example are a must in my opinion. Then, as you said, the local avoidance is simple and bad. I mean... what the hell Unity.

    As mentioned here, Jakob is missing. He was the only man truly helping here. Now he's gone and us, poor defenseless devs remain here... sad and desperate in these dark times. Is there anyone left to save us?
     
  4. Neriad

    Neriad

    Joined:
    Feb 12, 2016
    Posts:
    125
    Is there still no way to properly work around this besides using something else than unity's navmesh ? Would using A* solve this issue ?

    My problem is that I have a crowd (up to 1000 units or so), the behaviour looks good until I reach something like 150 units following the same destination point and they all just push themselves away and it looks ridiculous. I have tried many things to solve this but nothing has worked yet.

    I'll try tomorrow what @TomPo said but it looks pretty unnatural and I'd like to avoid such fix !
     
  5. Lynxbird

    Lynxbird

    Joined:
    Aug 19, 2018
    Posts:
    17
    This thread is old but my answer might help someone.

    Here it is what helped me, try playing with Nav Mesh Agent "Obstacle avoidance".

    What you described happens when both objects have their "priority" set to same number.

    Try assigning different numbers to your characters or try disabling it for some, it will solve the issue of them pushing each other. Now which character should have higher priority is up to you.
     
  6. juelzsantana123

    juelzsantana123

    Joined:
    Feb 28, 2019
    Posts:
    17
    very bad, unity simple dont see that path is blocked and need to repath
     
  7. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,758
    Your issue has to do with the AI's stopping distance/attacking distance, thats why they push you around. Stop blaming Unity.
     
  8. juelzsantana123

    juelzsantana123

    Joined:
    Feb 28, 2019
    Posts:
    17
    thats unity fault. if you write own script that will cutout part of mesh then if will avoid and make path. othervise it will bump or start to walk very slow
     
    EZaca and warthos3399 like this.
  9. juelzsantana123

    juelzsantana123

    Joined:
    Feb 28, 2019
    Posts:
    17
    Ok here it is.
    With basic avoidance you cant surround other agent like in game Warcraft3 because they will crowd and push eachother.
    When agent not able to push other -> surrounded unit wont be able to escape in this case.

    This package on github solves problem but not 100%

    https://github.com/jadvrodrigues/CustomNavMesh
     
    Last edited: Sep 5, 2022
    warthos3399 likes this.
  10. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,758
    May not be 100% but looks workable, dont think ive seen that GitHub package before, but then again ive never had this problem in my games. I just know that stopping distance/attacking distance is the cause of the pushing problem.

    Good to know about this package, who knows what the future holds, could be very useful in certain senerios :)
     
    juelzsantana123 likes this.