[PUN] syncronization

Options
Hello everyone.
First of all i want to apologize for my bad English. It's not my native language.

About problem.. I build simple race game using PUN.
As everyone knows, in any racer game all players need to see start race frame (after enumeration 3...2...1...GO).
This enumeration should be shown on each computer in the same time.

How i made it right now:
1) Check that all players are loaded into game scene.
2) Masterclient send RPC to each player and for yourself too (PhotonTargets.All).
3) In RPC function we started Timer coroutine on each computer.
4) After timer counter is more than 3, game starts.

On my own computer in several windows all works fine.
But on different devices rpc received with some different delay.
So, race starts on different times on a different devices.
How i can fix it using PUN?

Comments

  • dontonka
    Options
    Hello LemanRass.

    Yeah that's a tricky one. Dealing with multiplayer game that's require such precision will be hard with any SDK, not only with Photon, because of the of the delay communication might varies between players, as you pointed out, and also the speed of the device itself.

    Personally, in order to minimize the speed of the device that might vary between players, I would trigger the final Go from the Master client only, and not relying on every single player that proceed to the countdown to start the race. So it would be
    1) Master ---RPC---> Start count down
    2) All players are starting count down
    3) 3 .... 2 ..... 1 ....
    4) Master reach the Go ---RPC---> Start race

    But the main problem remain the delay difference between players. What you could do before the race is to send some RPC from the Master to all the players and they all acknowledge back, so this give your the round trip delay for all the players... you do an average for every player (maybe 10 times), divide by 2 to have only the one way delay, and when you execute 4), you take that information into consideration, so you could start a CoRoutine that start sending the start race RPC to player that has the longest delay first and so on (and waiting the proper time between player).

    That sounds complex but in theory that could work but i don't think it is that much. Good luck and let us know how it goes. This is my 2 cents, you are better to listen to what Photon expert says (eg.: Tobias). Maybe PUN has some API that helps you already to manage that, I don't know.

    Cheers,
    Don T.
  • I find an easy solution in
    PhotonNetwork.sendRate = 100;
    PhotonNetwork.sendRateOnSerialize = 100;

    and serialization timer by OnPhotonSerializedView function.
    Also after timer is end, i make this variables to lowest value to make my game more faster.
  • Tobias
    Options
    Leman: I am sorry to say, but having a sendRate of 100 will break when your game becomes more popular. It creates way too many updates/sec to be stable.
    You can try to base your timing on the synchronized PhotonNetwork.time. This timestamp is synchronized and hopefully on all machines +/- 20ms accurate, so there is no visual time difference for normal users.
    Have a look at the InRoomRoundTimer.cs. This starts rounds over and over but you get the idea and can use something similar for a start timer, too.
  • dontonka
    Options
    Hello Tobias.

    I did a BETA test this week and lagging issues was my main problem. So I need to fix this properly with proper send rate and interpolation, keeping in mind performance and 500 msg/room/sec. I would like your clarification here.

    In the code I can see this
    /// Less packages are less overhead but more delay.
    /// Setting the sendRate to 50 will create up to 50 packages per second (which is a lot!).
    /// Keep your target platform in mind: mobile networks are slower and less reliable

    Currently I use default values which are:
    [code2=csharp]private static int sendInterval = 50; // in miliseconds.
    private static int sendIntervalOnSerialize = 100; // in miliseconds. I.e. 100 = 100ms which makes 10 times/second[/code2]

    Can you suggest me any value for those 2 variables? I'm targeting mobile only. It the rule of thumbs always to have sendIntervalOnSerialize double of sendInterval? My game is an FPS, so no extrapolation, only interpolation, and proper update rate..

    I'll try to do some tests this week-end, but I would still want your opinion on this please :).

    Thanks,
    Don T.