Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Third Party Best practices for PvE using Photon 2 PUN?

Discussion in 'Multiplayer' started by Sapidus3, Sep 4, 2020.

  1. Sapidus3

    Sapidus3

    Joined:
    Aug 18, 2018
    Posts:
    6
    TLDR: what is the best way of having a bunch of AI-controlled enemies without killing the msgs/sec from a bunch of views.

    So I've tried out some sample projects and have a good idea of how to handle PvP and deal with lag compensation on projectiles.

    I want to do Co-Op PvE though, and based on the message traffic and the number of enemies I want onscreen at once can't give them all views. I was hoping I could get some feedback on how I THINK this should be handled and if I am completely off-base.

    Instead of having a view per enemy, there would be a single manager object with a view. It would transmit updates about the position and health of enemies from the master client. Everyone else would keep track of the "true position" of the enemies in this manager object when the receive the update and then lerp enemies towards where they should be.

    Their behavior is fairly deterministic assuming their targets are all synced. So I was thinking that the master client, instead of having the enemies move right away, would instead, after having them all pick a target wait 100ms (or somewhere around there), then make the RPC. That way all clients could all have the start of enemy motion be synced, minimizing any effects from lag. I could then hide this short delay by varying the animation speeds.

    Does this make sense? Is this how other people do it? Trying to do research it seemed like most of what I found was focused on basically just having Players with views and mostly just PvP. If people who have done this sort of thing before could give me some feedback it would be greatly appreciated.

    Thanks!

    (The project is basically a top-down dungeon crawler).
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,018
    What you describe is actually very close to what I'd recommend doing, too.
    As you plan to have multiple enemies on-screen, a manager to send the intentions and targets makes sense.

    I will ask our colleague Davin to chime in. Think his Simple Network Sync addon for PUN 2 would be a good fit here, as it features tick-based syncing. This should help start the AIs movement in a synchronous way.
     
  3. Sapidus3

    Sapidus3

    Joined:
    Aug 18, 2018
    Posts:
    6
    That addon actually sounds great. Reading through it, it seems like it does some stuff I was planning to do and then some stuff that I had not thought of but sounds like it will be very useful.

    A question though, it seems to be in Beta but I did not notice any issues logged. How stable / usable is it currently, if you know the answer to that?
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,018
    It's quite stable in the tests and scenarios we use it for and it's based off a first version, too.
    It's mostly called beta, because we don't have a lot of experience with it in other projects. As in: Does it cover requested features and is it understandable, etc.
    I'd recommend prototyping with it. Get a feeling for it first hand. Report what you like / don't like in the discord channel and then decide. It should save a lot of time and hassle.
     
  5. Sapidus3

    Sapidus3

    Joined:
    Aug 18, 2018
    Posts:
    6
    Thanks, part of why I decided to try out Photon was that I saw you guys seemed to be very active in forums and other places helping people out, so it is appreciated.

    In a week or so when I get a chance to properly prototype with it, I'll drop by your discord and let you know.