I am making a simple 2d real-time browser online game with an authoritative server (like any other
.io game). I receive game state snapshots roughly every 50 (40 - 70)ms. They consist of all visible game objects with positions, sizes, and colors. I have a state buffer where these snapshots are stored before they are processed. I decided that I want to render 100ms behind the newest snapshot I have. I have an
update function that is called every frame. It receives
deltaTime - time after the last call and
snapshotBuffer - array with all the snapshots in an order I received them. In an
update function I can set objects'
positions to fresh ones and this will automatically set their current positions to
my general question is:
What is the correct algorithm of consumption snapshots from the buffer in update function to get smooth interpolations and always stay behind the server the desired amount of time?
I have read all the related articles by Gabriel Gambetta, Gaffer on games and valve related to this topic, but I still can't figure it out