This repository is intended to study real time physics-based gameplay using deterministic lockstep with delay and rollback.
The following examples were performed:
In the 200ms
game on the right, it's really noticiable things teleporting after rollback caused by missprediction. This could be addressed by #37.
One last thing to emphasize is that even if you stop the video at the same frame, especially in the 200ms, you might see a slightly different simulation which is not an issue because eventually it'll rollback and correct the position. An determinism/implementation problem is noticiable at the level you can tell that both simulations are completely different without needing to pause it because a small error becomes big in no time.
The physics is being simulated by a deterministic cross-platform physics engine called Rapier.
The client/server communication is performed by Colyseus, a library built over WebSockets that creates a TCP connection, which basically means that we have guaranteed in-order delivery
The netcode uses deterministic lockstep with static delay and rollback, the basic idea is that we only send/receive inputs to recreate the exactly same simulation in all clients, that's why we need a deterministic cross-platform physics engine.
For more details about the netcode, take a look at the Deterministic Lockstep implementation doc.
Install dependencies from client
and server
:
./install.sh
Start in watch mode, it'll reload server/client after every change:
yarn watch
Note that after changing client code it'll take a while to transpile and you'll need to reload the html page.
Open localhost:2567/client
with a single or more browser windows to play
Controls:
Kenney Future
from Kenney Fonts by Kenney under license Creative Commons Zero, CC0. Note: original file .ttf
has been converted to .png
and .xml
for library compatibilityMIT