Hey, I'm working on a little Multiplayer game (up to 16 players) in Java using LWJGL for the Graphics and KryoNet for the Networking. A Chat and some easy things with KryoNet are no problem, I even can see the other players move arround. I'm working this way: The Client sends his position+current moving direction to the server which sends it to all Clients except the one that sent it to him. So the moving of each Client is controlled by the Client and can't be manipulated by the server. The problem is, that i want to add sth. like explosions which will force the players next to it to get thrown away, but how does this work?Should I just send the input of the Client to the Server and let the Server handle the movement of every Client on his own and send it back to All Clients? Or is there another possibility to do this?

I'm working this way: The Client sends his position+current moving direction to the server which sends it to all Clients except the one that sent it to him. So the moving of each Client is controlled by the Client and can't be manipulated by the server.

Server: Do the tick, and send (60 times per second?) stuff like playerpositions back. And never forget: DON'T TRUST THE USER!

Okay, I'll check Box2D (I forgot to mention i'm coding in 3D, Box2D is just for 2D no?)So collisions and everything else just gets managed by the server? When i send the input to the Server, how would it like manage the rotation of the camera the client has atm? or should i just send that too?

I have no idea More I think about it, more things come to my head If you sent lists, you might be sending individual entities + list. So it might be better to send individual. But then, when you send lists, you might be sending less bytes, because they might be somehow packed in that list. Unless someone tells you about their experience doing this, I think you should just try.

Okay, and I give each entity an ID to manage them on client side yes? So i send an object containing positions+movement (for interpolation) to each client using udp. I'll try this out with sending like 20 times per second. Or anyone knows how often minecraft is sending so i can take the same value?

- Separate your server simulation ticks into states. A state contains the position and velocity of all the entities in the simulator for a specific period of time. When you send the information to your clients specify the state too.

- On the client, do the same in reverse, create states based on packets you receive and store positions, velocity, etc. in them.

- Instead of extrapolating, interpolate between previous states. Add a 100ms lag to all your player. It might sound strange to add lag, but you will get stability in exchange (giving time to packets to get in). You could still extrapolate if you have missing states (intense lag).

- In my game I have 32 entities that I update 20 times per second. (640 small UDP packets).

- Since you are sending something every 50 ms, you could store all the packets to a specific player and send them in a batch (of 1400 bytes packets).

- To reduce bandwidth and packet count: add some line of sight detection, send only packets to players who can find the information useful.

- Use java.nio.ByteBuffers to pack your data. You can pre-allocate a big one and re-use it for all your packets (for both reading and writing packets).

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org