I'm creating a simple racing game (spaceships, no gravity) using p2.js, phaser and node.js.
What I have done:
Client receives world state from server:
- extrapolate other players based on latest velocity/position from server
- check if client-side prediction was correct - if no apply position from server and process inputs that server was not aware of.
- fixed physics step
Server:
- receives inputs from clients and apply
- fixed physics step
- sends world state to each client
Now I'm struggling with collisions between players. Colliding player is jumping all time during collision. I think it's because client-side prediction is not calculating similar results to the server.
Server doesn't know all inputs from player (lag).
Player doesn't have the same position of colliding player as the server (lag).
Combining this two makes the client to resolve collision different than the server and when world state arrives player has to make a big correction.