Properly interpolating between server state updates can get surprisingly messy. Since clients can’t always accurately predict the movement of objects, many games actually display the state of the world from a short time ago. This allows clients to show the game almost as if it were a movie—the client already knows what will happen before it does, and therefore can display it to the player with much better accuracy.
The first time I tackled interpolation, all I did was make the client lerp between the state updates it received from the server—no timing involved. This works fine when I connect from the same computer which the server is running on since there’s almost no latency in that case.
However, if packets are delayed, the client ends up simply extrapolating the previous movement because it doesn’t know what else to do. That’s not the end of the world in many cases, but especially when it comes to players in fast-paced games, showing movement precisely is pretty important, so I finally decided to implement proper interpolation.
As always, if you’re interested in more videos like this, leave a like (it really helps out with the YouTube algorithm), and consider subscribing. Also, come check out the Discord server where you can share your progress, ask for help, and hang out with other game developers.