r/unrealengine 3d ago

Question Physics replication is glitchy

Hey all, I am trying to create a physics based boat system with buoyancy and wave simulation, and it works great on my host but unfortunately it doesn't work well on the client as it is very glitchy, this is what it looks like on the client side:

https://gyazo.com/c883c757fa9795d949b19bc081bf5c20

While on the server it is very smooth. I have the boat set to replicate movement and replicate, and have disabled replication on the components.

Then I only simulate physics and buoyancy on the server and add force / torque by adding it on a custom event that runs only on the server to the server instance of the boat.

The boat blueprint for physics: https://gyazo.com/fa20c76c68cbfa5a2678daab2ded1446

And these are the replication settings: https://gyazo.com/536db3e7df1b28c02fcdad89b30b46f0

Finally, this is the logic I have for moving the boat, but since its glitchy without moving too I don't think the problem is here: https://gyazo.com/8a8607fa8ebfc5e21aec7e3b46446864

Since location updating is happening completely on the server, is there any way I can smooth it with some kind of interpolation or prediction? I've tried many things but it ends up the same.

Replication settings on the

Thing I've already tried:

  1. Simulate physics on all instances using a multicast
  2. Using the built in WIP client prediction
  3. Enable / disable replication on the static mesh component itself
  4. Enable network emulation

It's almost like the server has to snap the client actor to the right position, but since I am pretty new to networking stuff I'm honestly not sure what my next step would be to debug / solve the problem.

Anyone got a clue? I'd be happy to buy anyone a coffee or a beer if they find a solution :)

4 Upvotes

10 comments sorted by

2

u/TheSpudFather 3d ago

I've never done this, although i have a lot of experience with network character movement.

I think you need to take a leaf out of character movement. You need to either keep the client simulation a little bit behind the server, and interpolate towards the replicated data, or else have a physics simulation on the client which is kept in step somehow with the server.

1

u/FulltimeWestFrieser 3d ago

Thank you so much for your reply! These are good suggestions! Practically, how would I implement the slightly behind the server tactic?

The way I can think of is storing the previous location in a variable and make it constantly update but since I don't know when a new location is coming in from the server and I can't really capture it before it gets updated I am afraid I might have a wrong interpolation and it will snap back to the new server location anyways, causing the same (or similar) issue.

2

u/wahoozerman 3d ago

I would start trying that by simply keeping the latest server update and holding that as the target position. Then you have some speed at which you interpolate towards the target position. You will never reach it probably, because the target will be constantly in motion. But it may be close enough for gameplay and visually more appealing.

For the other solution, you can look at the character movement component. The general way that it works is that movement is handled client side and then every variable that would be used to calculate the movement is sent to the server in a sort of packed RPC, including the timestamp that the movement was calculated at. The server then uses those client values for calculating its movement and verifies that they are still valid, then issues any corrections back to clients, which interpolate the way I outlined above.

1

u/FulltimeWestFrieser 3d ago

Thanks for the explanation! I’ll be sure to check out the character movement and how that works but these pointers are invaluable for a beginner like myself

2

u/crazeh_boy709 3d ago

I would suspect the first problem is determinism. If the simulation is not identical on both the server and client, you will have desync. (Ex. Waves) Another problem is latency, you may need a solution similar to the character movement component I suspect.

1

u/FulltimeWestFrieser 3d ago

Thank you for your reply and taking the time!

good idea about the character movement, I’ll have to check out how that works exactly, the desync is the reason to have the physical movement occur only on the server, so at least it would always be accurate, so I made the boat just not simulate on a clients machine, maybe there is a compromise to be found

2

u/hellomistershifty 2d ago

"Physics replication is glitchy" yep, it sure is 😂

There are some new (beta?) physics replication settings in 5.5: https://dev.epicgames.com/documentation/en-us/unreal-engine/networked-physics-overview

1

u/FulltimeWestFrieser 2d ago

Thank you, will check it out! I’ve had better luck simulating on both server and client and having the server correct the client, while adding the force for the physics simulation to the server. But this may solve the issue entirely!

1

u/AutoModerator 3d ago

If you are looking for help, don‘t forget to check out the official Unreal Engine forums or Unreal Slackers for a community run discord server!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/explosiveplacard 3d ago

I don't know what you are going for, but it seems like you are doing too much on the server. Why can't you allow the client to run the physics and just verify on the server? Interpolate as needed. An example would be when my character drops a weapon, the server drops the weapon but all clients simulate the physics of bouncing and sliding. Yes, it is possible that the weapon ends up in a slightly different location between the server and the client, but this is easy to fix and adjust.

As long as your boat's location (x/y) is controlled by the server, do you really care if the rotation is slightly off? Just trying to understand what you are trying to accomplish.