What type of information is usefull to send?
Hello all!
Me and my friend is writing a small 2D space shoot-em up. You control a space ship over a map. The "single player" version of the game is almost done, you can fly around, shoot and so on. Input device is the keyboard.
This was supposed to be a multiplayer game but at the start of the network implementation we encountered some problems. What is usefull to send to other players? For now we are using Winsock and a client/server approach.
Every ship could send its position on the map to the server every frame, this seems wierd. Or, we could just send what key each player presses/releases and let each client (or the server) maintain calculation of the positions of all other ships.
Or? what is the best way to do stuff like this? We are both rookies in the network world but there are many many fast action games out there that handle this. Suggestions please..
there are 2 main ways you could go about it:
1) The client decides where it is and what its doing and then sends updates to the server letting the server know where it is
This way has problems of hacking because the client could tell the server it was moving wherever the player wanted .. but i doubt u are worried about hacks ;-)
2) The Client is like a GUI (graphical user interface) and doesnt really decide where it is.. rather it says to the server things and the server then tells the client where they are (and all the other clients).. it would go something like this:
Client: Rotate to 90 degrees
Server: You are at 90 degrees and at position 10,50
Client: Set Trust to 100%
Server: You are at 90 degrees and at position 11,50
Server: You are at 90 degrees and at position 12,50
Server: You are at 90 degrees and at position 13,50
etc
that kinda thing.. except dont send test messages of course :-p
the other issue which your concerned about it.. like when do you send updates to the clients.. you could
1) Send updates as oftern as possible saying something like
server - > Client1 : Client2 is at 1,2 45 degrees
server - > Client2 : Client2 is at 1,2 45 degrees
server - > Client1 : Client1 is at 10,5 80 degrees
server - > Client2 : Client1 is at 10,5 80 degrees
etc
This will you quite a bit of bandwidth up if you had a lot of people connected over a dialup modem, but if it was like 8 people over a LAN then to be honest it wouldnt matter and may be easier for you
2) Send "state" updates when required.. ie something like
Client1: Rotate to 90 degrees
Server -> All clients: Client1 is at 90 degrees
Client1: Set Trust to 100%
Server -> All clients: Client1 is at 100% thrust
This way only state information about the clients is sent so each client then works out where all the other players are based on the info it has about their direction and thrust.. this will reduce the effect of any lag because each players ship will be moving ever time the client updated the other players ship on their own computer.. the problem is that if say there is a half second delay on the message getting sent to a client saying that another player has stoped.. they have traveled for an extra 1/2 second on that players view and so isnt really where they really are.. you takle that by having the server track where all ships are (u need to do that anyway so it can calculate collisions etc) and every 1 or 2 seconds send out a message to all clients saying where the other players Really currently are
there i think thats enough woffle
~tim
1) The client decides where it is and what its doing and then sends updates to the server letting the server know where it is
This way has problems of hacking because the client could tell the server it was moving wherever the player wanted .. but i doubt u are worried about hacks ;-)
2) The Client is like a GUI (graphical user interface) and doesnt really decide where it is.. rather it says to the server things and the server then tells the client where they are (and all the other clients).. it would go something like this:
Client: Rotate to 90 degrees
Server: You are at 90 degrees and at position 10,50
Client: Set Trust to 100%
Server: You are at 90 degrees and at position 11,50
Server: You are at 90 degrees and at position 12,50
Server: You are at 90 degrees and at position 13,50
etc
that kinda thing.. except dont send test messages of course :-p
the other issue which your concerned about it.. like when do you send updates to the clients.. you could
1) Send updates as oftern as possible saying something like
server - > Client1 : Client2 is at 1,2 45 degrees
server - > Client2 : Client2 is at 1,2 45 degrees
server - > Client1 : Client1 is at 10,5 80 degrees
server - > Client2 : Client1 is at 10,5 80 degrees
etc
This will you quite a bit of bandwidth up if you had a lot of people connected over a dialup modem, but if it was like 8 people over a LAN then to be honest it wouldnt matter and may be easier for you
2) Send "state" updates when required.. ie something like
Client1: Rotate to 90 degrees
Server -> All clients: Client1 is at 90 degrees
Client1: Set Trust to 100%
Server -> All clients: Client1 is at 100% thrust
This way only state information about the clients is sent so each client then works out where all the other players are based on the info it has about their direction and thrust.. this will reduce the effect of any lag because each players ship will be moving ever time the client updated the other players ship on their own computer.. the problem is that if say there is a half second delay on the message getting sent to a client saying that another player has stoped.. they have traveled for an extra 1/2 second on that players view and so isnt really where they really are.. you takle that by having the server track where all ships are (u need to do that anyway so it can calculate collisions etc) and every 1 or 2 seconds send out a message to all clients saying where the other players Really currently are
there i think thats enough woffle
~tim
~ Tim
August 02, 2002 09:01 PM
For movement send directional vectors, and send this info whenever the directional vector changes.
quote:
Original post by Anonymous Poster
For movement send directional vectors, and send this info whenever the directional vector changes.
But they probably change all the time. Just send them often..
-------------Ban KalvinB !
if you send the update vectors at about 10 frames a secobnd things should be pretty smooth. just interpolate the data to the framerate. now your probably saying thats not often enough, well carmack thinks its enough for quake. you can decide yourself. every once in a while the server sends absolute positions to make sure games stay in sync, otherwise missed data is extrapolated from previous snapshots and the last full absolute snapshot from the server.
also make sure you game is using a fixed time step system. its VERY important otherwise the networking will be many times more difficult to get working correctly.
the server is always final judge. it decides whether someone is moving too fast (ie by sending packets with hacked vectors) or whether a collision takes place. the server handles data like energy as well. technically only the following for each ship (with in range of the client) should need to be sent:
acceleration vector (ie direction and speed)
velocity vector (ie deirection and speed)
special status (ie any powerup that may cause a visual change)
positions of projectiles and their vectors.
clients only send there velocity vectors when they change (up to a certain update rate) and things like fire are sent immeditaly. though you have the client say "start fire" "end fire" so multiple shots require only two packets. single shots can still be done with one packet, the client decides whether its mulitple shots or single shots based on how long the fire button is down and if multiple shots would be sent. be careful with this however since extra shots amy be fired due to lag.
also make sure you game is using a fixed time step system. its VERY important otherwise the networking will be many times more difficult to get working correctly.
the server is always final judge. it decides whether someone is moving too fast (ie by sending packets with hacked vectors) or whether a collision takes place. the server handles data like energy as well. technically only the following for each ship (with in range of the client) should need to be sent:
acceleration vector (ie direction and speed)
velocity vector (ie deirection and speed)
special status (ie any powerup that may cause a visual change)
positions of projectiles and their vectors.
clients only send there velocity vectors when they change (up to a certain update rate) and things like fire are sent immeditaly. though you have the client say "start fire" "end fire" so multiple shots require only two packets. single shots can still be done with one packet, the client decides whether its mulitple shots or single shots based on how long the fire button is down and if multiple shots would be sent. be careful with this however since extra shots amy be fired due to lag.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement