Search Unity

Way to stop the obstacle avoidance pushing other agents around when they bump into each other

Discussion in 'Navigation' started by DromoDesigner, Apr 29, 2022.

  1. DromoDesigner

    DromoDesigner

    Joined:
    Mar 27, 2016
    Posts:
    73
    Hello. I am using Unity's navmesh system to make an RTS game with tanks.

    When the tanks get close to each other, the avoidance system kicks in and they try to get out of each other's way. However, they often bump into each other and end up pushing others out of the way. This shouldn't be possible with vehicles as heavy as tanks, and it looks unnatural.

    Is there a way to have the navmesh agents try and avoid each other, but not bump into each other, and if they do, definitely not push each other around?

    I have tried altering the obstacle avoidance priority, but there is still at least always one tank that pushes others out of the way.

    I have also tried altering the rigidbody, for example making stationary tanks work with gravity and making them really heavy. I have also frozen all rigidbody constraints. However, other tanks are still able to push them out of the way with ease.

    At the moment, when tanks stop moving I have made a navmesh obstacle appear under them, which helps with avoidance. However, this only works if they are stationary - moving tanks can still be pushed around by others.

    Any ideas or suggestions for how to solve this would be greatly appreciated!
     
  2. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    Hey.

    Check out this video from @ChrisKurhan


    The avoidance system of the Unity Navigation System is very limited, not sure if you can really achieve what you are aiming for. The best trick from the video is afaik to increase the NavMesh resolution and play around with the avoidance priority, e.g. give them all the same priority, which should in theory prevent pushing in the first place.

    Though you might get another problem. If you increase the number of tanks when using NavMeshObstacles. Each time you switch on a NavMeshObstacle on or off the path of each NavAgents gets invalidated. Having too many NavAgents switching NavMeshObstacles will lead NavAgents stuck, as their path gets invalidated while it's still calculated.

    You should probably take a look into A* Pathfinding Pro as it has a lot more options to work around your issues.
     
    ChrisKurhan and DromoDesigner like this.
  3. DromoDesigner

    DromoDesigner

    Joined:
    Mar 27, 2016
    Posts:
    73
    Hello - thank you for the information. Very interesting video.

    Unfortunately, I have tried giving the tanks all the same avoidance priority, and they just end up all pushing each other out of the way.

    I did not know that about NavMeshObstacles - sounds like its not a good idea to use them the way I am.

    I will look at using A* Pathfinding - I already have it, but needed to use the Unity navigation system as an important asset I have uses it. I will try and see if I can get it working with A*.

    Appreciate your advice!
     
  4. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    @DromoDesigner can you post a short video showing the circumstances that your tanks push one another? Ideally from the scene view, with at least 1 tank selected and the Navigation window open so you can see all of the debug information from the NavMesh?