speed = (currentTime - startTime) / (endTime - startTime)
frame = Date.now()
const speed = (frame - positions[0].frame) / (positions[0 + delay].frame - positions[1 + delay].frame);
- The interpolation factor
speedrepresents the position between the two most recent positions in the positions array. frameis the current frame of the game.positions[0].frameis the frame of the most recent position in the positions array.positions[0 + delay].frameandpositions[1 + delay].frameare the frames of the two most recent positions, with a delay offset.- The formula
(frame - positions[0].frame) / (positions[0 + delay].frame - positions[1 + delay].frame)calculates the interpolation factorspeedas a value between 0 and 1, based on the current frame and the frames of the two most recent positions.
interpolate point = (1 - speed) * from + speed * to
clientPlayerInterpolated.pos.x = (1 - speed) * positions[1 + delay].x + speed * positions[0 + delay].x;
clientPlayerInterpolated.pos.y = (1 - speed) * positions[1 + delay].y + speed * positions[0 + delay].y;- The formula
(1 - speed) * positions[1 + delay].x + speed * positions[0 + delay].xperforms the linear interpolation between the x-coordinates of the two most recent positions. - The formula
(1 - speed) * positions[1 + delay].y + speed * positions[0 + delay].yperforms the linear interpolation between the y-coordinates of the two most recent positions.
const speed = (frame - positions[0].frame) / (positions[0 + delay].frame - positions[1 + delay].frame);
clientPlayerInterpolated.pos.x = (1 - speed) * positions[1 + delay].x + speed * positions[0 + delay].x;
clientPlayerInterpolated.pos.y = (1 - speed) * positions[1 + delay].y + speed * positions[0 + delay].y;