I'm developing a JavaScript Multiplayer Game (Using NodeJS and Socket.IO). The problem I'm having is, on a Player's movement, the Event with the X and Y positions is sent to the server and then to all the other Players on that Server. Now, on a 60 FPS Machine, the event is sent to the server 60 times a second, resulting on smooth movement on all other Machines with 60 FPS. However, on a 30 FPS Machine, it's only sent 30 times a second, resulting on jumpy movement on higher FPS Machines (E.g. 60 FPS).

Is there any way to resolve this problem?


  • Render loop, network traffic, and update loop should always be decoupled.
  • Look into the publish/subscribe model.
  • Your game probably has 'levels' (even 'the entire world' could be a level')
  • Treat each level like a 'channel' (think IRC #channel, Twitter #topic, etc)
  • When a user enters a level, they subscribe to that level's channel. Similarly, when they leave the level (log out, move out of range, etc) they unsubcribe from that channel.
  • When a user performs an action warranting notification to other players, he sends a publish to his level#channel indicating his intent.
  • If the server OK's the movement, the server then broadcasts to all players within the moving player's subscribed channel of the movement and/or new position.
  • Each player subscribed to level#channel gets the update on the object in question, and makes the position change.
  • When the render loop (separate from your network loop) draws everything, moved objects will have updated positions, and will appear to have moved.

You should interpolate the positions and rotations and possible other stuff on the client side and you should send data to the server/from the server at a fixed rate, 16-30 updates per second is fairly enought.

Besides that, your client should never send any position/speed information to the server because this would allow the players to cheat very effectivly. Remember that the server have to be always the authority.

  • \$\begingroup\$ So in regards to the Server handling movement, do I just send the key strokes and let it send the movement data back to the Client, and every other Player? Also, so a solution to my original problem would be to have, say, moving and direction variables sent to the clients about each other every update, and if moving is true, move them in the specified direction until moving is set back to false? \$\endgroup\$ – Oyed Jul 31 '13 at 18:34
  • \$\begingroup\$ the client send to the server only which key was pressed (input), the server send to the clients the current status of the objects, e.g. position, speed, ... \$\endgroup\$ – Quonux Jul 31 '13 at 19:22
  • \$\begingroup\$ Thanks, I'll look in to that method then. But, still, what about my original problem? Do you think there is a better way then what I proposed in my first comment? \$\endgroup\$ – Oyed Jul 31 '13 at 19:29
  • \$\begingroup\$ yes there is, its my way (sry for being so direct), if you send only delta information (which button each player has pressed without the current position) you have the problem that the positions are more and more different from the other players (because of timing issues) \$\endgroup\$ – Quonux Jul 31 '13 at 19:40
  • \$\begingroup\$ Sorry, I'm just a little confused, I can see how this would help prevent hacking etc. but how would it affect my original problem? \$\endgroup\$ – Oyed Jul 31 '13 at 19:47

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.