I have a ball with physics enabled which runs nice on server,but since “replicate movement/actor” doesn’t replicate objects with physic I have to use an multicast event that replicates the new position to the clients each frame(tick).
This does look good when testing inside editor,but as ping increases you start to see the ball stuttering.
I tried to add Interp to smooth movement over those slower frames,as you can see below…But it just makes it stutter bit differently.
The problem is with interpolation, your interpolation is based on lagged position and speed, and will always have to “catch up” (which is when the sudden jump/stutter happens).
To properly replicate physics, I think the physics calculations themselves would have to include network smoothing timestamps, which in Unreal Engine, currently they don’t.
There may be a plugin available on the marketplace for this but I’m not sure.
Some people have solved this problem by changing the usual arrangement of the server version of the actor being authoritative, to the client version being authoritative (so the owning client’s version of the simulation doesn’t have to wait for a round-trip update from the server to update the ball position), which with some other techniques allows cheating but eliminates most of the stuttering, as long as the client that owns the ball doesn’t have a bad upload speed.
If this were me facing this problem, AND the ball is supposed to be controllable by a player, like in those Marble Arena
and Monkey-Ball type games, I would try the following first before trying to do the very hard problem of solving network prediction and smoothing for physics engine that doesn’t support it:
Make a new Ball blueprint that is not based on Physics Simulation at all, but is instead based on the CharacterPawn base class.
Make the half-height of the capsule the same as the radius, effectively changing the collision area to that of a ball.
Tweak all the Character Movement and Walking Movement properties of the CharacterMovement component so that it acts as much like a ball as I can get it to (higher inertia, lower friction and deceleration values, etc.
Add a sphere Static Mesh component that fits the collision capsule, and leave the skeletal mesh blank.
Program the spherical mesh to rotate in a way that matches the movement of the ball (detect when it is on the ground or airborne, spin at the rate it would if it was rolling, in the right direction, etc.
But again, ONLY if it is supposed to be controllable by a player.
The CharacterMovement is designed to smoothly predict and catch up lagged network updates across all machines participating, simply by factoring the values used in the Add Movement Input node, the Add/Set Control Rotation node, and the movement mode that is currently active on the CharacterMovement component (walking, swimming, flying, etc.) without you having to implement RPC nodes for each movement.
So this makes it great for networked games, but I am only sure of it for pawns that you want to be able to directly control the movement of.
If this is supposed to be for something like a grenade bouncing off walls and rolling for example, or a pinball or soccer ball simulating around a field, then I’m not sure this will solve the problem for you in the way you need (but you can try it and let me know how it goes)
In that case see if you can find a way to make the Soccer Ball client-authoritative. That means that if you spawn the ball on the client machine then the server obeys that client as to the speed and position of the ball, and reports it to everyone else. I don’t know how to do that, but that is how others have fixed the problem. Just remember it does make cheating possible from the client that is authoritative (of course then cheating is always possible from a listen server then, too)
A further problem with networked physics in Unreal is that PhysX engine is not deterministic, so if you repeat the exact same conditions on another run of the scenario, it may turn out differently, so that makes it even more divergent between multiple machines. I imagine you’ll need to make it so only one machine is simulating and replicating to all the others who are interpolating and predicting ahead. In that strategy it still makes sense to simulate on the server, just not on any other machines, but you may have to create your own network smoothing and prediction.
As Unreal changes over to Chaos physics engine this might be partly resolved, IDK. I just heard things and am passing them on.
Hm,never thought about making it client-authoritative to prevent cheating,but might it be viable as last resort.
For now the ball is spawned only on server (with physics on) and replicated to clients with the default UE4 checkbox…It looks ok but I believe it would brake with more players online.
Yeah, I’m too hoping Chaos brings something new in this department too.