I am working on a real-time multiplayer soccer game.
Currently, on my game, I created an architecture like that:
- Every client has a copy of the game state, also the server has it too.
- Clients send their input vector (joystick data) to the server. (Local player uses the current input and moves).
- Client waits for other players' input, once that data arrives I set rigidbody speed and direction. Then, it goes smoothly.
Things I use:
- UDP (has lower ping)
- Tick rate: 32 (increasing tick rate fixes this issue most of the time but not everyone's connection is strong and sending many packets in a second causes a ping issue)
Problem is:
Sometimes, the server and clients get de-sync and this causes every client sees another copy of the current game.
What I've tried:
- Tried to increase the tick rate, but this only caused a connection with higher ping + packet loss.
- Lerp between two states. This caused players seem like moving at different speeds
- Lerp + Jitter. This caused players always see the game in a past state.
- If client and server positions are different than a delta-x, use the server's position (normally this can fix the issue but sometimes server and client get de-sync every 4 tick and transporting object in 4 tick cause a very laggy/not smooth visual)
What is the best method to fix or handle this de-sync? And why it is happening?
Is it typical it happens in almost every 4-5 tick? (~9 times in a second)