If we were to only run our game in a LAN environment, we would probably never expect low latency or any significant packet loss. While many are blessed even with good Internet connections nowadays, from time to time, problems still happen. One of the tricks to try to mitigate these problems is to use interpolation for entities on the client side.
This means that rather than just applying the position and rotation the client gets from the server, the client will move towards the target position and rotation in steps.
Perform the following steps to interpolate between the player positions:
To simulate some network problems, set
framerate
on the server to10
.If you connect to the server now, the movement will be noticeably jerky.
We replace the contents of the
controlUpdate
method ofClientPlayerControl
with the following lines to apply the interpolation:float factor = tpf / 0.03f; spatial.setLocalTranslation(spatial.getLocalTranslation().interpolateLocal...