Let's say you want to create a 2D game where a character can shoot a bullet. You have the same code running on the Client and Server (JavaScript so it's exactly the same code).

If the client and the server create the same bullet instance at the same tick X, with the same position, direction and velocity, is it safe to assume that the bullet will end on the same place on both the server and the client? Does the server need to send back the exact position at which the bullet collided, or can the client just predict that as it uses the same physics and same bullet initial data.

Can the bullet hit the target on a different tick, or at a different position on the server from the client? My initial thought is that this shouldn't happen, but could this happen because of a different CPU architecture or a different JavaScript engine?

  • \$\begingroup\$ What happens if the client is cheating? That should answer your question. \$\endgroup\$ – Maximus Minimus Oct 11 '17 at 9:22
  • 2
    \$\begingroup\$ Don't trust the player. Always assume the worst - that players will try to cheat. In a multiplayer game you need an authoratative server. \$\endgroup\$ – Christian Ivicevic Oct 11 '17 at 9:56
  • \$\begingroup\$ The server is authoritative, if the client is "cheating" he will only see the changes on his side. @LeComteduMerde-fou It does not answer my question, I don't care if the client messes up with his own game if it does not affect the server or others in any way. The server is still the one deciding who wins, who got killed, etc... If you mess up with the client, you may see that you won, but it will only be on your own client. \$\endgroup\$ – Cristy Oct 11 '17 at 10:29
  • 1
    \$\begingroup\$ What happens, if the player has a high ping (200ms for instance) and one of the other characters position doesn't match the one on the client side, what do you do with the differences in the outcomes (as an example, let's say the other character jumps off a cliff, but the client only gets the information about the jump, when the other character is already falling? How do you handle that?) \$\endgroup\$ – Bálint Oct 11 '17 at 10:50
  • \$\begingroup\$ Assuming your server is on a really low ping connection with the players (like LAN) and you can guarantee that the code will work exactly the same independent of the frame rate (using ticks etc. instead), you can assume that it's going to end up at the same spot. Though as @Bálint said, on high ping situations your players will feel that they were cheated against. \$\endgroup\$ – John Hamilton Oct 11 '17 at 12:02

What you're describing is usually called "lockstep", it's very common in RTS multiplayer games, like Starcraft.

Lockstep Network Implementation in Unity

Usually most multiplayer games will try do to some smoothing and prediction to prevent laggy behaviour.

| improve this answer | |
  • \$\begingroup\$ I already have this implemented, I just want to know if the physics simulation could be non-deterministic due to different CPU architectures or JS engines. \$\endgroup\$ – Cristy Oct 12 '17 at 14:36
  • \$\begingroup\$ Imo this is more of a design decision, do physics impact gameplay in any significant matter or are they purely "cosmetic"? If we're talking bullets, I'd just do a line whenever a gun fires and timestamp the hit and broadcast to players - the physical bullet should only be an effect that's played clientside. \$\endgroup\$ – ag4w Oct 12 '17 at 14:44
  • \$\begingroup\$ It's not cosmetic, the physics impact the game as any collision permanently changes the world for that specific client. My question is if I can simply assume that the physics simulation is deterministic. \$\endgroup\$ – Cristy Oct 12 '17 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.