Multiplayer physics lag

I was able to replicate the lag problem by just moving a platform the players are standing on. It’s a network latency issue, not performance issue.

Explanation

What I think is happening is that when the client drives, because the client’s character isn’t actually moving on it’s own (it’s standing on the ship), the server doesn’t know that the client’s character should move. So, from the server’s perspective, the client’s character stays in the same place. When the ship movement is replicated to the client, the client’s character follows the ship and is replicated back to the server many frames after the ship has already started moving on the server, causing lag.

From the client’s perspective when the server drives, both the server’s character and the ship move at the same time and are replicated to the client correctly.

You may be able to solve this by attaching/parenting the driver to the ship like you would a vehicle. That way, all players have the driver attached locally so it won’t lag.


Other ideas

Relying on physics like this may not be good. Think about when you have more complex situations like walking on stairs, going inside the ship, large collisions with other ships, or having physically simulated objects on the ship (which will never go to sleep because they’re always moving). I also noticed in your videos that the client’s camera is more bouncy & unstable than the server’s camera (which seems perfectly still).

Consider putting all objects on a ship in “ship space” like I do here. The player is actually hidden under the map (but for a space scene, you can set it to hidden in game). The player you see is a “clone” that copies the transforms and animations of the real character. The real character is always upright, whereas the clone moves & rotates with the ship because it’s parented to it (it’s a skeletal mesh component in the ship blueprint). This keeps you from having to worry about complex interactions & physics on the ship because they all happen in “ship space.” Though, it does have the problem of how to “detach” from the ship when you want to float out into space and interact with things outside the ship. It’s possible, but can it be done seamlessly?

Haven’t tested it in multiplayer, but it should work the same: just copy the real characters’ transforms to clones inside the ship. Because the real characters aren’t actually moving, you shouldn’t get any lag problems.


If not that, you should probably consider attaching the (real) characters to the ship (by parenting, setting location manually, etc.) only when they’re standing on it, and detaching them (while keeping the momentum of the ship) when they’re not.

So basically just the same the solution for attaching the driver to the ship, but for all players whenever they’re standing on the ship.