Search Unity

All NavMeshAgents Compete for the destination...

Discussion in 'Navigation' started by DanVioletSagmiller, Mar 16, 2021.

  1. DanVioletSagmiller

    DanVioletSagmiller

    Joined:
    Aug 26, 2010
    Posts:
    204
    I have an RTS I'm working on, and when I have multiple units selected, and then set a destination, I effectively call "agent.SetDestination(point);", where all the 'point' values are the same for each agent.

    The problem is that as they get there, they begin to 'dance':


    I've solved this in the past be using StoppingDistance, but the user might select 1 unit, where the stopping distance should be 0.1, or they could select a hundred units where the stopping distance should be more like 20. But when I try establishing a stopping distance that scales with unit count/size, Once the first ones stop, at the farthest distance from the target, the one behind it starts pushing them out of the way, which is highly unrealistic in my case, with tanks.

    Any advice would be great. - Thanks!
     
  2. Jimbo_93

    Jimbo_93

    Joined:
    Mar 2, 2021
    Posts:
    7
    You need to make a group move function. Sample positions in a grid around the target destination until you have found enough valid positions for all units.

    Could also sort their pathing out so the closest unit picks the furthest position available, which would help to prevent them pushing through eachother.

    Also, nice looking game :)
     
    DanVioletSagmiller likes this.
  3. DanVioletSagmiller

    DanVioletSagmiller

    Joined:
    Aug 26, 2010
    Posts:
    204
    Thanks @Jimbo_93. That seems easy enough. I'm thinking of another possibility, and that is to have units change order. I.e. when sent to a target, all the units sent there keep a record of where they were sent, even after they arrive. And just allow them to arrive in mass via the default method. If a unit is blocked by another unit on the same pass, then they will swap destinations. Or grab everything and see if its open to move it in a v formation closer to/around the target.

    I'll need to do some experiments here. :)
     
  4. Tomasz_Pasterski

    Tomasz_Pasterski

    Joined:
    Aug 12, 2014
    Posts:
    99
    I resolved this in my RTS project by making all selected units to take random position around destination.
    If at specific random destination is any other object, then other random till it is free.

    Also this is first problem you encounter while making RTS using Navmesh agnets, there will be more like local avoidance while, typical RTS order attack-move for example. But fear not, was heard there is dedicated unity team to navmesh, they will work on this somewhat forgotten component.