How to develop multiplayer game using box2d

Hi, everyone

I am developing a racing car using box2d engine, I have 2 ideas and test them:
One Way:
1. use box2d engine to simulate in every client
2. used java as server, server only accept keyboard and collision and so on events, then server dispatch all such events to all clients (please ignore the client cheating )

instance description: now we have client A and B, they are in the same ground. so client A could see car A and car B, also client B.
car A and car B could be synchronized, but a few time, car A's position in client A is different with car A's position in client B.
I think the reason is that: box2d use float precision, and I use 30 as PHYSICAL SCALE.

The other Way:
1. use box2d engine to simulator in every client
2. used java as server, it runs jbox2d engine, server accept keyboard and collision and so on events, then server dispatch all such events to all clients
3. server also runs a thread to correct client's position every 2 secs.
instance description: the position of car is different between server and client(position of car in server and client can't be synchronized), I think the float is not very accurate.

Could you some one give some advice or some example which uses box2d in network game.
here is some reading i recommend.
it may not directly answer your questions but it is informative. its also not specific to box2d.

keep in mind that box2d was not built with networked multi-player in mind. and may not be your best choice for network physics.
however given a little leniency I'm sure it can be done.
The best is to do hard word on client, so if you ignore cheating (like bzflag, it's a free game) the best way is P2P:
1. client connect to server and get other player IP(for a P2P network, else every message is replied to all other client by server)
2. every client do it's own physic,
    EXAMPLE:
    if client A shot it send the message to server and all other client
    client B compute is hit by shot and send death signal to server and client
3A. the server doesn't have physic, just do some statistic/ban/whatever or as "proxy" for who is under a firewall/nat (cannot listen to port, so cannot directly connect client-client)
3B. basic anti-cheating: server has it's own physic, but it's used only when there are two or more client with discordant data (like A say have hit B but B don't die, A and B ask for a verify to server, and server reply to all client the response)( i like that way:-) )

read here http://www.box2d.org/forum/viewtopic.php?f=3&t=4614, remember you have to fight with different architecture, so every, X seconds you have to upload all the visible world to clients.
sketchbookgames wrote:
here is some reading i recommend.
it may not directly answer your questions but it is informative. its also not specific to box2d.

keep in mind that box2d was not built with networked multi-player in mind. and may not be your best choice for network physics.
however given a little leniency I'm sure it can be done.



I agree with you, do you have any idea or information to choose network physics lib (open source) ?
lestofante wrote:
The best is to do hard word on client, so if you ignore cheating (like bzflag, it's a free game) the best way is P2P:
1. client connect to server and get other player IP(for a P2P network, else every message is replied to all other client by server)
2. every client do it's own physic,
    EXAMPLE:
    if client A shot it send the message to server and all other client
    client B compute is hit by shot and send death signal to server and client
3A. the server doesn't have physic, just do some statistic/ban/whatever or as "proxy" for who is under a firewall/nat (cannot listen to port, so cannot directly connect client-client)
3B. basic anti-cheating: server has it's own physic, but it's used only when there are two or more client with discordant data (like A say have hit B but B don't die, A and B ask for a verify to server, and server reply to all client the response)( i like that way:-) )

read here http://www.box2d.org/forum/viewtopic.php?f=3&t=4614, remember you have to fight with different architecture, so every, X seconds you have to upload all the visible world to clients.


I have downloaded your code to learn, I think it is very useful. Do you think it could be used in java and flash (box2d) ?
That is the basic concept for creating a mini online game. That is very useful for starting the first online game using Box2D. Nevertheless, it would be great if there is a template for the basic codes of the online game.



online roulette
Well this tool will be a useful thing for people who is creating online game

Christine Bounds
Master Cleanse Secrets
Spam 🙁
jun wrote:
Hi, everyone

I am developing a racing car using box2d engine, I have 2 ideas and test them:
One Way:
1. use box2d engine to simulate in every client
2. used java as server, server only accept keyboard and collision and so on events, then server dispatch all such events to all clients (please ignore the client cheating )

instance description: now we have client A and B, they are in the same ground. so client A could see car A and car B, also client B.
car A and car B could be synchronized, but a few time, car A's position in client A is different with car A's position in client B.
I think the reason is that: box2d use float precision, and I use 30 as PHYSICAL SCALE.

The other Way:
1. use box2d engine to simulator in every client
2. used java as server, it runs jbox2d engine, server accept keyboard and collision and so on events, then server dispatch all such events to all clients
3. server also runs a thread to correct client's position every 2 secs.
instance description: the position of car is different between server and client(position of car in server and client can't be synchronized), I think the float is not very accurate.

Could you some one give some advice or some example which uses box2d in network game.


Hi , i recon its an old post , but i think i can add a little to it for those interested...

While developing multiplayer games the concept of client-side-server is the most important as i don't think simulating box2d on each client is a good approach due to lag (say delayed impulse for jump may cause undesirable results).
So the best way according to me is to make box2d run on a single client while updating the actors on each client (kinda like MVC) this solves problems such as
1> Inconsistencies caused due to lag
2> Cheating
and is relatively simpler to code.

Original thread: https://box2d.org/forum/viewtopic.php?t=4704