1
\$\begingroup\$

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?

\$\endgroup\$
10
  • \$\begingroup\$ What happens if the client is cheating? That should answer your question. \$\endgroup\$ Commented Oct 11, 2017 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\$ Commented Oct 11, 2017 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
    Commented Oct 11, 2017 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
    Commented Oct 11, 2017 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\$ Commented Oct 11, 2017 at 12:02

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\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
    Commented Oct 12, 2017 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
    Commented Oct 12, 2017 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
    Commented Oct 12, 2017 at 16:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .