Home » Android » java – How to synchronize Play Services Real Time Multiplayer

java – How to synchronize Play Services Real Time Multiplayer

Posted by: admin May 14, 2020 Leave a comment

Questions:

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?

How to&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.