Search Unity

Third Party Sync a randomized game object over Photon

Discussion in 'Multiplayer' started by NonPolynomialTim, Sep 25, 2014.

  1. NonPolynomialTim

    NonPolynomialTim

    Joined:
    Sep 17, 2014
    Posts:
    7
    Hello everybody,
    I am currently trying to create a multiplayer 2D endless driving game using Photon Networking. The issue I am having is that I am randomly generating terrain and I have no idea how to keep it in sync across the network. I have tried using RPC's but that just calls a new random terrain segment on each client, which leaves everyone with a different terrain. Is there a way to send all of the information concerning a game object across the network so that everyone can have the same bit of terrain?

    Thanks in advance!
    Bentley
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    In best case, your terrain-generating code uses one seed and then generates the same level from that every time and on all devices. When Random is initialized with the same seed, it should generate the same sequence of values.
    This is the best way, actually. You only need one number to init all player's Random.
    In worst case, you have to make sure you generate enough level to send it over to the other clients which will skip their generation and just use what one of them did. You need to generate level ahead of time, cause lag might delay when the others got it.
    RPCs are ok for that.
     
    aksh627 and NonPolynomialTim like this.
  3. NonPolynomialTim

    NonPolynomialTim

    Joined:
    Sep 17, 2014
    Posts:
    7
    Thank you so much! This helped a ton, although I ended up just using an RPC to check whether or not the player was the designated "host" and then if so I fired another RPC for the GenerateTerrain() method using the host's random values for the parameters, leaving everyone with the same generation. Thanks Tobiass!