Was hoping to get some help with physics-based multiplayer. We're trying to make a multiplayer game with physics objects players can interact with. Elements of physics gameplay will be competitive or collaborative, so players need to be able to interact with the objects in near real-time.

Unfortunately, I've hit a few snags. I've managed to get perfect physics playback but not in a way that players can interact with the objects. I've also managed to get the reverse: players able to interact with objects in real-time but at the cost of synchronization.

My goal is to get physics synchronization close-enough but with players able to see results immediately. What I mean is that the player can interact with physics objects immediately and corrections from the server will keep things in sync. As long as the players can't tell, then it's good enough.

To show the concept, I’m using a ball to display rocket league style physics.

Attempt 1: Hermite
After reading through Glenn Fiedler’s articles on networked physics, I got near real-time perfect playback between server and clients.

In this version I have perfect playback by sending position, velocity and time. In the first screenshot below, I drew a red line where the ball is hitting the wall. Everything looks great.

The problem is the clients can’t interact. They are just watching a replay so many milliseconds later. If the client player launches themselves into the ball at high velocity they will come to an immediate stop, and then the ball will launch just briefly later. The reason for this is because at the time the player hits the ball, the server has not had a chance to both calculate the hit and respond.

The operations are
  1. Client player launches into the ball
  2. Client sends position to the server (can be skipped if the server extrapolates the position)
  3. Server calculates physics hit launching the ball forward
  4. Server responds to client
  5. Client receives and draws updates (about 60ms later on a fast connection with little lag).

I spent a lot of time trying to do extrapolation on the client and server, but physics is not deterministic in UE4, so resyncing showed a lot of errors, teleportation and flickering over time.

Attempt 2: Force Correction
I got much closer to real-time interactions with force correction. In this version instead of setting location based on hermite interpolation, I use the information to figure out where the ball should be and add a corrective force.

This gets playback on clients while still allowing players to interact with the ball. If a player launches into the ball, the ball immediately launches and the player continues forward. The server still calculates the hit and sends it back. The client hit and server hit don’t calculate the same, so a corrective force is added to the client to move the ball where it should be.

When the ball is not hitting anything, this works great. For collision, this fails. If the ball hits any hard object the corrective force will turn the ball away before the hit occurs. If the ball hits a hard object on the server, and the client is not there yet, the ball will curve away on the client without hitting the object.

In the second screenshot below the ball curves away from the wall before hitting the wall.
Video of the issue - https://youtu.be/YV7NTF9JJPU (ball curves away from walls or the ground)

How Rocket League Does It
I tried to read up a lot on how other games do this. I watched & read numerous GDC talks and research papers/articles. Rocket League integrated a deterministic physics engine into Unreal instead of using the built-in one. Unfortunately, we don’t have the resources to do that.

I haven’t really found many answers beyond using a deterministic physics engine.

I have a few ideas for moving forward. Any input/advice is appreciated.
  1. Read hits different from when the ball is not colliding. Use hermite interpolation when the ball is colliding but forces when not.
  2. Use hermite unless the player hits the ball, then switch to forces until the ball is away from the player.
  3. Record hits and calculate my own physics with forces instead of relying on the built in physics.

Thank you for reading and your comments! It's really appreciated.