Sending keyboard input over UDP in a network game

I am implementing network asteroids over UDP. I was going to limit the custom introductory messages that the client sends to just state changes. Therefore, only send a message when the arrow or space bar has a down or up key. This will significantly reduce the number of packets sent from the client.

However, now that I've re-read Gaffers' article on network physics, and it's more difficult to make UDP messages reliable, I am rethinking. He claims:

The key to making this input stream tolerant of packet loss and out of order delivery is the inclusion of a floating point time in seconds value with every input rpc sent. The server keeps track of the current time on the server and ignores any input received with a time value less than the current time. This effectively drops any input that is received out of order. Lost packets are ignored.

So it doesn't care if the packet is lost. Now I think that a vital package that indicates that a keydown to push the ship forward can be the one to be lost and never resent, thus breaking the game.

So am I right in saying that instead the client is forced to send more regular (down to every physical update, 50 times per second) dumps of the actual keyboard state, rather than state changes to fit this pattern, which is tolerant of packet loss? Or is there a nobler path?

+3


source to share


3 answers


Based on the answer to an identical question I asked on gamedev: https://gamedev.stackexchange.com/questions/26840/send-regular-keyboard-samples-or-keyboard-state-changes-over-network , the consensus seems to be , should only send the state of the keyboard when it changes (for the duration of a key press or just a key). This results in almost no traffic. This is necessary to ensure the reliability of these messages. This will be a challenge to achieve, as the motive is critical to timing. those. even though the client may move on to move its own player (ala's client-side forecast), other clients must be informed of their competitor's state change, via the server and in "real time".



0


source


As I said in my comment, there is no answer to these.

But in your case, I probably won't transfer keystrokes, but the physics changes instead:



  • Carrying over only changes in physics, for example. when the acceleration of objects (players, asteroids) changes and changes in the general state of the game (asteroid / player explodes, shots, score)
  • If you do, also pass in the current position of that object to compensate for the delay (even with 3ms, the positions of the objects will be slightly different) and update the positions of the corresponding objects (sometimes it can look like objects will bounce a little, but almost every game has this problem ).
  • Everything else (physics of the world, for example, gravity) can be calculated on the client itself and should not be transmitted over the network.
+2


source


Another way is to shake handshake packets and retry until a handshake is reached. Of course, you will need to do it both ways. In the old days of the show, this could be done with four control lines, two at the end.

0


source







All Articles