authoritative gamestate

Hi,

To be able to raycast server side i need game states to be able to timeshift and execute the raycast.
What would be the best way to achieve this ?
Would i just fill a game state buffer from the client inputs or do i have to monitor movement for each player on the server and use that ?
Thanks :slight_smile:

I will explain how I do this in my game, a stripped down version of the networking code can be found here: http://forum.unity3d.com/threads/102903-Submitting-Lidgren-Authorative-Networking-Example, but I will try to give you a high level overview in this thread.

Assume one server (S) with two clients (C1 and C2) connected. I sync the clocks of C1 and C2 to the clock of S, this is done by sending the S clock as the first time in every package sent to any client, which the receiving client then adopts as the base for its own time, incrementing it locally until it receives a new time-stamp from the server. Discrepancies in the S clock received by the server can be smoothed out using a leaky integrator, code for this can be found in the NetworkTime class in the exampled I linked above.

C1 sends a “FORWARD” command to S, which S acts upon, every 45ms S sends the current position for every player to all clients, with the position that is sent the current S time-stamp is attached (as previously explained) and S also records the each position and time-stamp locally, keeping a buffer of the 20 last ones (this can be seen in the NetworkPosition.Send method in the example)

So, C1 and C2 have been sending commands for moving to S for a while, and now C1 sees C2 on his own screen and shoots at him. C1 plays the sounds and animations for shooting locally, but does no hit calculations himself. Instead C1 sends a command to S for FIRE, his own local time-stamp (which is based on the S time-stamp received in every package from S) and his own local rotation (This can be seen in the UserInput and NetworkClient classes in my example).

S receives the FIRE command from C1, he looks a the time-stamp attached in the fire command and then finds the two best matching (the one before and the one after the FIRE command time-stamp) saved states in the buffer “sent states buffer” for each player, interpolates between them using the time-stamp attached and then uses the rotation to do a ray-cast for to do the actual hit/miss calculations on S (this can be seen in the NetworkFire class in my example).

i can’t seem to find the NetworkFire class, am i missing something ?

Sorry the file is named NetworkActions and not NetworkFire.