Synchronized random values at multiple GameObjects

Hi,
I have multiple ammunition spawn points.
Each of these should spawn the same (random) weapon on every client, and after some random time spawn again a random weapon.

Everything is working except that the Random is not really Random.
I get the same Random values again after restarting the game.
Is there a possibility to use a different seed for each new start of the game? (Which is synchronised over the network too, so that all clients have the same values)

Thanks in advance,
John

Comments

  • Hi @John05,

    You can try this in an OnSyncedStart method:
    TSRandom.instance = TSRandom.New(TSRandom.Range(1, 1000));
  • John05John05
    edited March 2017
    Thanks for the answer @JeffersonHenrique
    But this is causing the same behavior.
    Try this code in an OnSyncedStart method to see what I mean:
    var x = TSRandom.Range(1, 1000);
    Debug.Log("TSRandom Seed: " + x.ToString());
    TSRandom.instance = TSRandom.New(x);
    It's always returning the same number, no matter how often I restart the client, even if I use another second client. Random is in this case not returning random numbers. I assume you use the TrueSyncManager.DeltaTime to calculate these random values? And this value is always the same on the start of the game. (0.02) -> according to
    Debug.Log(TrueSyncManager.DeltaTime);
  • You need to seed the random with a truly random number, e.g. current time or ticks or whatever.
    That number you need to communicate from the client master to all other clients before starting the simulation.
  • Thanks for your advice @Geminior .
    But shouldn 't TSRandom do this for me? (Currently TSRandom isn't random at all when used in the OnSyncedStart method).
  • Hello @John05, TSRandom is random but for every fresh start it needs to give the same results. In your case you change the seed to be the number of runs for example, if you are running a second time then the seed used could be "2". You just need to make sure that all clients use the same value.
  • John05John05
    edited March 2017
    Hi @JeffersonHenrique,
    Thanks for the clarification.

    I try to achieve the behavior that @Geminior wrote.
    Therefore I am using SyncedInstantiate to create a prefab that has this RandomManager script on it.

    Can you please have a look and tell me what I am doing wrong?
    I am not able to receive an input from another player.

    Btw. how to get the owner.Id of the MasterClient from a client, that is not the MasterClient himself?
  • Hi @John05, can you pack some simple project with this issue? The script seems to be ok to at least receive inputs.

    As TrueSync uses the same id as PUN you can access the master client and get his id from that reference.
Sign In or Register to comment.