Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to synchronize Play Services Real Time Multiplayer

I am developing an online version of the popular game Pong using Libgdx. I've started using Google's Realtime Multiplayer service to send the game data between players, but I can't figure out how to resolve the synchronization problem I am facing.

The information sent at the moment is the player's paddle, so when I move I send my new position to the opponent. At the time the opponent receives it, time has already passed and sync is lost.

I understand that there should be maybe some waiting time between movements using the slowest connection, but how do I make it look smooth then?

like image 280
Enpi Avatar asked Apr 22 '17 16:04

Enpi


People also ask

How do multiplayer games sync their state?

The client sends input to the server at T0 to emulate the game state at T1, so the client can then render the game without having to wait for the state update from the server, which only arrives at T3. This approach only works if the following takes place: The game state updates logic are deterministic, ie.

How real time multiplayer games work?

In a real-time match, the players are connected to each other simultaneously in a single game session where they exchange data messages. This form of match is suitable for implementing any type of game that requires live participation.

How do multiplayer games send data?

Packets and Protocols: Online games communicate through a packet-switched network, like the Internet, where communications are broken up into small data units, called packets, which are then transmitted through the network from the sender and reassembled on the other side by the receiver.

How do real time games work?

Real-Time is perhaps the simpler concept, in that a game that runs in real time has events that update…in real time. If there is a clock in the game, it runs at 60 seconds per minute. Characters move, actions are taken, and choices are made with the clock running consistently and incessantly.


1 Answers

There is not definitive answer to this question but there are various strategies which people adapt to solve this situation.

Going from using UDP protocol (if you are using socket based communication which I will recommend you because every ms matters in realtime games. I think google api has UDP which is unreliable messaging. Again I have no experience with google-realtime-api) for message exchange to interpolation, dead reckoning, client side predictions etc are just few.

This is a very vast topic to answer here. When I made my multiplayer tank based game I did a few things to make things look a little smoother.

  1. Used UDP protocol for sending movements to server.
  2. I will keep two entries on client side for a player. One is the current value and one is the value to set. Then I will multiply current value with a smoothing factor like 0.3f till the time its not equal to the value to set. (This helps in reducing jitters)
  3. I would send important messages via TCP.

The points I mentioned describes what I did in my game but can be used in any. Although I would suggest you to read articles on this website called Gaffer on Games

Again this area is huge and no answer can help you out. I did my thesis on this topic and still can't give you a definitive answer. You will have to read a lot of articles and model what you learn according to your needs.

like image 87
Sneh Avatar answered Oct 25 '22 15:10

Sneh