I am trying to interpolate players in a multiplayer game like so:
var lastTime = now - (1000 / config.serverUpdateRate);
for (var i = 0; i < players.length; ++i) {
tmpObj = players[i];
var total = tmpObj.t2 - tmpObj.t1;
var fraction = lastTime - tmpObj.t1;
var ratio = fraction / total;
tmpObj.x = UTILS.lerp(tmpObj.x1, tmpObj.x2, ratio);
tmpObj.y = UTILS.lerp(tmpObj.y1, tmpObj.y2, ratio);
}
The server update rate is the frequency with which the server send the player positions. The x2 is the newest position and x1 is the position from the previous update.
Now this works fine on my localhost and on an empty server. But as soon as the game server has around 60 people on it, it begins to stutter. I am assuming that this is because the positions are coming in at an inconsistent rate. How can I adjust for that in my interpolation?
You can see the issue in action here: http://moomoo.io
I have tried to simply interpolate without lerping, but the movement felt too floaty. Also client prediction is not an option in this case