# Interpolation Jitter

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

• How are you assigning x2 and x1? I assume t2, x2, y2 are all the most recent snapshot from the server. Are you treating t1, x1, y1 as the previous snapshot, or as the interpolated state of the object at the time the newer snapshot was received? – DMGregory Mar 25 '17 at 16:54
• Professionally, I come from a different background (EE / Signal Processing), so I'm not sure if this is applicable. Have you heard of a Kalman Filter? You can use a Kalman Filter to track e.g. radar targets over time. The idea is that the position information is noisy and the Kalman Filter takes in the noisy measurements over time and uses them to reduce the error due to noise. The data you have might be "perfect" position information but slightly unknown time information. But I think it's mathematically the same. – derstander Mar 27 '17 at 0:07