Reputation: 18035
I'm developing a multiplayer game in Unity3D and I'd like some help with synchronization. One of the players act as a server and everybody else are clients. At some point in the game, all players have 10 seconds to answer a question before they move on to the next step of the game. The time it takes them to answer the question is recorded and used to figure out the fastest answer, so it is very critical that all clients start their timers at the same time.
What is the best way to structure this as far as messaging goes? And what information will these messages contain?
Things I've tried/thought:
Thanks in advance.
Upvotes: 2
Views: 763
Reputation: 229
You could have the server give the signal to start the timer, along with a DateTime. Instead of starting the timer at the same time as the message, give the clients a DateTime occurring a few seconds after the message is sent. That way the clients won't start the timer as soon as they get the message, allowing for those with lag to 'catch up.' (e.g. The signal is sent at 7:00:00 AM, containing the time 7:00:05. As the clients recieve the message, they wait to start the timer until 7:00:05, so all the timers can start at the same time.)
Upvotes: 1
Reputation: 229
Depending on who you're developing the game for, you could always just let the clients handle the timing. Have the server give the signal for the clients to display the question and start the timer, and then wait for the responses. Each client can then time the user and give the time to the server along with the user's answer. As long as the server gives the clients a 'buffer' of a couple seconds, it should recieve all the answers with accurate timing, no matter how much lag there is.
The only problem with this is that, again depending on your audience, users could potentially tamper with the sent data.
Upvotes: 1