我正在尝试在在线游戏中使用lerp功能。我通过有一个缓冲区列表来做到这一点,我将每个服务器更新附加到一个列表中,然后控制内容,这是一个示例:
movementBuffer.unshift(gameUpdate); //when a new update is received
//in the main loop
timeElapsed += delta;
lerpPerc = timeElapsed / updateRate; //percent which is lerped to
if(lerp > 1){ //when the lerp is finished, the states that were just lerped are removed from the buffer
movementBuffer.splice(prevData.length - 2, 2); //remove the previous states from the buffer
state1 = prevData[prevData.length - 1];
state2 = prevData[prevData.length - 2];
timeElapsed = 0;
lerp = 0;
}
for (i = 0; i < state2["players"].length; i++) {
// update the players
prevY = state1["playery" + state["players"][i]];
prevX = state1["playerx" + state["players"][i]];
x = state2["playerx" + state["players"][i]];
y = state2["playery" + state["players"][i]];
//lerp to the new x and y
playerCoords[recivedData["players"][i]][0] = lerpF(prevX, x, lerpPerc);
playerCoords[recivedData["players"][i]][1] = lerpF(prevY, y, lerpPerc);
}
这里的问题是lerpPerc
的执行速度太快,因此它基本上删除了缓冲区中的所有项目,没有什么可忍受的。我在这里做错了什么?