我有一个node.js服务器,它接收客户端位置并每100ms向所有人发送一次。在客户端,我已经实现了客户端预测,协调和实体插值。问题是如果延迟变得更高,则插值不平滑。有一个恒定的抖动,玩家有不同的速度。这是我的插值代码:
function updatePlayers(player) {
var t1 = previousLastUpdate; // timestamp of the previous postion
var t2 = lastUpdate; // timestamp of the actual position
var tickRate = t2 - t1;
if (tickRate < 100)
tickRate = 100;
// sometimes the difference is lower than 100(which is the server update rate) and
//this also creates jitter
var renderTime = Date.now() - tickRate;
if(renderTime >= t1 && renderTime <= t2) {
var portion = renderTime - t1;
var percentage = portion / tickRate;
// interpolate from last known position to actual position
var interpX = lerp(player.lastX, player.getX(), percentage);
var interpY = lerp(player.lastY, player.getY(), percentage);
player.setPrevX(interpX);
player.setPrevY(interpY);
}
}
所以,我的问题是:如何摆脱这个问题?我不能使用航位推测,因为球员会快速改变方向。