Search Unity

Question Synched Navmesh Agents?

Discussion in 'Netcode for GameObjects' started by hippocoder, Apr 3, 2022.

  1. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Is there a plan to have networked agents so that large cooperative type games are possible, with less traffic or do I have to figure all this out manually?

    Any existing materials or examples I can look at for this? With 8 players larking around and some 30 odd enemies in a level, you can see what a big problem this might be.

    Also keeping things in sync would be very difficult too.


    Obviously none of this is difficult if bandwidth is not a concern, but it is with a lot of enemies that all need to path.
     
  2. luke-unity

    luke-unity

    Joined:
    Sep 30, 2020
    Posts:
    306
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Thanks! but will it be the same path for each machine? What I mean is I'm not sure if navigation is deterministic in destinations for each CPU, and if I should just send the corners as it were.
     
  4. luke-unity

    luke-unity

    Joined:
    Sep 30, 2020
    Posts:
    306
    The path might be slightly different on each machine. The NetworkNavMeshAgent periodically sends corrections including the correct position from the server to the clients so that if they deviate from the servers path they will be adjusted. But you will still get some movement artefacts in some cases. To achieve full determinism in a multiplayer game not just navigation but anything would need to be fully deterministic. To achieve that you'd have to even replace floats as floating point types are not deterministic across machines. The methods I'm familiar with for doing this are:

    1. The approach from NetworkNavMeshAgent. This is great if you have a lot of units and want to save bandwidth and you don't need fully accurate positions.
    2. As you mentioned you can send the full path corners whenever a unit calculates a full path. This approach can work very well. In addition to the path corners you'd also store the start position when the unit started moving on the path and then finding the right position is just a matter of interpolating along the points of the path.
    3. In many cases just regular position synchronizing can work just fine. For larger worlds an area of interest system can be used to hide units from the player which are outside their field of view.
    4. Create a fully deterministic game (determinstic lockstep) and have every client calculate paths and move themselves. This is not something that Netcode for GameObjects supports.
     
    hippocoder likes this.
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Thank you, I suspected as much, but your replies are extremely helpful even so.