Sign in to follow this  
TrieBr

UDP packets in player sync

Recommended Posts

I was reading this amazing article:
http://gafferongames.com/networking-for-game-programmers/what-every-programmer-needs-to-know-about-game-networking/

From what I understand, whenever you press a button, you send the keypress to the server while at the same time your client begins the prediction of the movement.


I have a question that may or may not be simple. Are these packets sent over TCP, or UDP? If it's done over UDP (for faster speed primarily), what happens when a packet is dropped? It would miss the keypress by not receiving the dropped packet which could cause inaccurate results.


Also, when the packet goes to the server and is rebounded to the rest of the clients, I assume the end-clients would need to do some interpolating of some sort because of latency?


Thanks in advance!

Share this post


Link to post
Share on other sites
Quote:
Original post by TrieBr
I was reading this amazing article:
http://gafferongames.com/networking-for-game-programmers/what-every-programmer-needs-to-know-about-game-networking/

From what I understand, whenever you press a button, you send the keypress to the server while at the same time your client begins the prediction of the movement.


It depends. You could send the keypress (as the article probably suggests) or you could send position updates if you trust the client.

Quote:
Original post by TrieBr
I have a question that may or may not be simple. Are these packets sent over TCP, or UDP? If it's done over UDP (for faster speed primarily), what happens when a packet is dropped? It would miss the keypress by not receiving the dropped packet which could cause inaccurate results.


UDP isn't "faster". But the nature of UDP and how it handles lost packets is suitable for games, and twitch games in particular. If a packet is lost you resend it until it gets ACKED, just like TCP does automatically. ENet, OpenTNL, RakNet etc are layers ontop of UDP that implement this (and a bunch of other features!).

Quote:
Original post by TrieBr
Also, when the packet goes to the server and is rebounded to the rest of the clients, I assume the end-clients would need to do some interpolating of some sort because of latency?

Thanks in advance!


Like the first question, this depends on your game. Lockstep games (RTS's) do it the way you describe, by rerouting the command packet. They are always in sync though. Most twitch games (FPS's for example) do not however, they send state updates on each player with velocities, position, fireing-state and then interpolate/extrapolate. But the difference here is usually that if a state-update packet is lost, it doesn't get resent. Why? Because when it finally arrives it will be too old already and a new update will be sent.

There was a good document from the designers of OpenTNL on this, something like the "Tribes Networking Model". I think the Unreal guys also released a similiar paper. Google them, they're really good. :)

Share this post


Link to post
Share on other sites
The type of game I'm making is an action platformer. Wouldn't the "twitch" me vulnerable to hacking/cheating? With the lockstep, the server has authority of the movements. You also mentioned the "twitch" method is used in most FPS games, but based on the article I read, it looks like the lockstep is used.



For an action platformer, what method would you recommend?

Share this post


Link to post
Share on other sites
Quote:
Original post by TrieBr
The type of game I'm making is an action platformer. Wouldn't the "twitch" me vulnerable to hacking/cheating?


It wouldn't.

Quote:
Original post by TrieBr
With the lockstep, the server has authority of the movements.


Lockstep doesn't mean the server has authority. Lockstep just means (basically) that all clients have to stay in sync, have the full game state, and only advance to the next tick when all clients are ready to do so. This means you can get away with only sending commands or keypresses. You cut down on bandwidth.

Drawbacks are that if one client is behind (lagging) all others have to wait. It's also prone to cheating in some games because all clients know more than they have to, which makes it possible to maphack.

"Twitch" is used in Quake, Counter-Strike, Tribes, Unreal etc. Almost always ontop of some UDP layer. You send game states unreliably, and drop ones that do not arrive since the next one will be more recent.

You can either let the server be fully authorative (Tribes, Unreal), or not (Half-Life/Counter-Strike) in which case people can use speed-hacks and stuff like that. The server can do periodic checks to see if the player has moved too far in the last few ticks, but it's definatly not perfect.

Quote:
Original post by TrieBr
For an action platformer, what method would you recommend?


The method used in Tribes/Unreal, but really it depends on how fast-paced your game is. But I'm biased.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this