Legacy GM Help with box2d networking

P

ProcrastinationIsADrug

Guest
I have created a basic client and server game where the client can pass inputs to the server and the server will move their character accordingly and then pass the x, y and rotation of the object back to the client so the character can be drawn.

I have been trying to implement box2d instances by doing all the physics calculations on the server and drawing the objects to the client. I can't get the client to receive the data from the server, this is probably just from inexperience in writing networks.

Are there any tutorials or projects I can look at which deal with networking box2d or any advice on how I should do this?
 

Phil Strahl

Member
Running the whole physics stuff on the server and only updating object positions on the client is a good idea. I would shoot a steady stream of UDP packets with the instances' position and rotation. Of course you need a good protocol and compression for that as it might introduce lag, so you might only want to transmit the changes instances' positions each frame and the entire scene, maybe once every 10 seconds to be on the safe side. Just avoid TCP/IP for that, as you never know when those packets will arrive. With UDP, you can't be sure that they all do (or in what order, so make sure to also transmit some sort of timestamp), but it's much faster for games.
 
P

ProcrastinationIsADrug

Guest
Running the whole physics stuff on the server and only updating object positions on the client is a good idea. I would shoot a steady stream of UDP packets with the instances' position and rotation. Of course you need a good protocol and compression for that as it might introduce lag, so you might only want to transmit the changes instances' positions each frame and the entire scene, maybe once every 10 seconds to be on the safe side. Just avoid TCP/IP for that, as you never know when those packets will arrive. With UDP, you can't be sure that they all do (or in what order, so make sure to also transmit some sort of timestamp), but it's much faster for games.
Thanks for the reply, I actually fixed what I was doing wrong and now have it implemented. But I will try to look into using UDP instead of TCP for this.
If I'm updating the instances' positions every frame, what do you mean by updating the scene every 10 seconds?
 

Phil Strahl

Member
Sorry, I didn't make it clear enough: I meant to send a snapshot of the whole scene (= all instances' positions and transformations) every 10 seconds to be on the safe side, and in between those only the updated transformations of changed objects.
 
Top