Advertisement

Collisions between players in multiplayer racing game

Started by May 07, 2016 11:45 AM
0 comments, last by hplus0603 8 years, 6 months ago

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.

That's correct. Handling player/player collisions is one of the hardest things to do in networked game design.
The higher the latency, the more you have to be able to "hide" the bad effects of client mis-predictions.
If you're using a web browser and websockets over TCP, you're almost guaranteed to have a higher latency than a native, UDP-based game would, too, making the problem more noticeable.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement