I'm building a multiplayer snake-like game with Javascript. I'm having problems with the precision of the opposite players location not reacting fast enough. Which in turns makes the worm "crash", but only for some players, where the change in position happened too late due to latency.

My current game logic sends the change in direction, eg: "Up","Left" as soon as player #1 reacts.

Player #2 then receives Player#1 new direction, and sets his worm to now travel "up" (the direction received).

Since this introduces latency and that the change in direction might be applied too late, i'm wondering what other possibilities is available?

One might be to send current coordinates, or have the game loop on the server aswell, to make sure all movement changes is synced properly.

  • 1
    \$\begingroup\$ While the question is good, it still lacks research effort. You should look around this site and internet for "Lag compensation" and "Network prediction" techniques. gamedev.stackexchange.com/questions/6645/… This is quite nice from here. This has been asked so many times, that i report it as a duplicate. \$\endgroup\$ – Katu Aug 26 '13 at 13:02
  • \$\begingroup\$ Thanks, all of you, this is the first game i have ever written, so my lingo is not that good. I tried searching for the wrong words I guess, trying things as "latency correction" and similiar. I just didn't know what it was called in the gaming community :) \$\endgroup\$ – Anders Aug 26 '13 at 14:28

The best you can do is to make sure that you send as little data as possible while making sure that it's worth sending. As for the coordinates - I'd say that you can give it a try as I don't really understand why you haven't done that by now. So try sending both the direction and coordinates to the server which in return sends it to the other players. I guess that you could try checking the data on the server to make sure that no one is sending fake data or manipulated data.. ie.. check if the direction and location are a possible option for the player before sending them to the other players..

  • \$\begingroup\$ This is my first game ever, so I dont really know what options I have. I'd like to read some more about the topic, but I think I googled the wrong combination of words, since I don't know what the gaming community use as lingo for the situation. The link provded by @Katu was very helpful, and i'll look it up! \$\endgroup\$ – Anders Aug 26 '13 at 14:32
  • \$\begingroup\$ I now send "I turned at this coordinate, and now i am at this coordinate" and I can then correct the other clients who might have guessed that i was traveling beyound the coordinate i turned on. \$\endgroup\$ – Anders Aug 28 '13 at 9:28

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.