LWJGL, KryoNet

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? ???

-Thanks for Answers :slight_smile:

Look in your server code for “sendToAllExcept”. This sounds like the issue.

Explosions should be done using box2d. They the easiest thing though.

This is exact how you should do this, handle everything with your server, and send info playerpositions and stuff to client.

Tasks:
Client: Render, send input to server (there are a few exceptions like chat)
So don’t handle the input in the client, like you are doing now:

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

Good luck with your game!

The server shouldn’t be sending 60 packets a secod for every single entity :frowning:

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?

yeh, 60 times a second for each entity seems a bit too much, could I just send an object which contains all Entities? like an ArrayList or something?

I completely agree.

I personally use updates every 0.333 seconds with added interpolation for movement. I can hold several hundred player entities within a small space quite easily.

Many games update their entities only 20 times per second and interpolate the results when rendering at 60 fps (e.g. minecraft).

So I send the position of the entity and the direction it’s walking so that the client can calculate where it’s going until he receives new positions for the entity?

So should I send the position of each entity seperately or just put them all into an arraylist and send that arraylist? would that even nake a difference?

I haven’t done lots of networking (Made only a simple chat :D).

I have no idea :smiley:
More I think about it, more things come to my head :smiley: 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.

Send the position of each entity separately. And use the UDP functions built into Kryonet.

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?

works fine for now with 20 times per second but i think this might not be perfect for an Realtime Action RPG, any suggestions how to make it “faster” and “smoother”?

Some suggestions:

  • 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).