Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

A* Pathfinding in Multiplayer?

Discussion in 'Multiplayer' started by ARares, Jul 13, 2017.

  1. ARares

    ARares

    Joined:
    Mar 18, 2016
    Posts:
    167
  2. fvde

    fvde

    Joined:
    May 15, 2014
    Posts:
    19
    What keeps you from doing it? Ideally you could consider to centralize AI decisions on the hosting machine (server or hosting player) in order to prevent different behavior on the clients. Then you could sync the resulting routes between players.
     
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    You surely can. We're using it for our multiplayer game.
     
  4. Leoo

    Leoo

    Joined:
    May 13, 2013
    Posts:
    96
    AI should only be loaded, activated or used on the Server/Host side, Zombies would move towards players on the Server/Host Scene, and each should sync position and actions to all clients.
     
    fvde likes this.
  5. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,314
    you could also sync destination of navmesh every one sec, so it will do pathfinding on both client and server, it will be smoother than syncing position 10 time per sec
     
  6. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    244
    I'd be careful about this. Nav mesh is not deterministic and lots of funky stuff can happen when agents bump into each other. Its probably fine-ish though
     
  7. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,314
    yes its been used in ummorpg and it work fine while it save lot of BW
     
  8. PHambone06

    PHambone06

    Joined:
    Mar 15, 2021
    Posts:
    1
    How did you get it to follow multiple targets? is there a tag or something I would apply to all players so it chases the closest one?
     
  9. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    There's nothing built-in like that, but everything can be implemented

    This was back in 2017, so as far as I remember, implementation ended up like this:
    - Server overlap checked via physics query. (Technically, even distance check should work);
    - Server calculated path, sent results to the client;
    - Client interpolated results, plus applied error correction (force set some position, rotation etc);

    So basically everything detection wise should be on the server, and client only received results.