|
Actually sending absolute positions over udp is really nice. Since the absolute position contains all the information you need for the state, you dont need to rely on relyability. You just apply any position udp packets which are more recent than the last one applied. If a packet is lost, the next arriving packet will be able to fix any missing informtion, and old positions that come in can just be thrown out. In general I think the best is to have clients send inputs to the server, have the server do the object logic, and then send positions of the objects to connected clients at a set interval.
And then yes, you will want to do too "tricks" on the client. Incoming positions for other players need to be smoothed out. If say, you get position [5,5] at time 0 seconds, and then the next position you get is, say, [25,5] at time 3 seconds, you dont want to just warp him to 25,5. Instead you want to over, maybe, the next 1.5 seconds, move him from [5,5] to [25,5].
Finally, for the players object, you want to apply the inputs to his local object as soon as they are made. You will have to work out how to deal with the server correcting the clients position if he makes a mistake in his prediction of where he should be.
Beyond that, you will want to optimize everything to fit your game. A general rule is, if something doesn't need to be sent, don't send it, and if something doesn't need to be reliably sent, don't send it reliably. Using udp, you will want some protocol to ensure the few message types that do need to be reliable (chat messages) actually arrive.
|