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?
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With