erincatto / box2d

Box2D is a 2D physics engine for games
https://box2d.org
MIT License
8.05k stars 1.51k forks source link

How do I simulate same result within server-side and client-side? #675

Closed Lai-hung closed 3 years ago

Lai-hung commented 3 years ago

How do I keep the server and client with same result? I try to coding a turn-based game with Box2D. Players only can shoot body in client-side, and client-side send shoot RPC to server-side, finally server-side generate result by arguments of physics and random number(gerenate by server-side).

Situation 1: Many body is static in the world, only player's body are dymanic. First I simulate the result by server, and send the physics arguments to client-side to let render, but client-side can not get the same result. So I try to trace Box2D, and I find out continuous collision detection (CCD) cause different results. Because my game don't have body with high speed , so I disable CCD, and I success. Is there have any way can let me enable CCD and generate the same result only by physics arguments in client-side and server-side?

Situation 2: Like situation 1, but some body are automatic move and affect the results, is there have any way can let client-side and server-side generate the same result?

I try to record position of player's body in every game tick, and send it to client-side to render, and render result is same with server-side. But this way cause the network packet is too large, and can't use within situation 2.

erincatto commented 3 years ago

Did you ask this question on Discord or Reddit?

https://discord.gg/NKYgCBP https://reddit.com/r/box2d

Issues are not the place to ask questions.

Lai-hung commented 3 years ago

Ok, I will ask the question on Discord and Reddit.

Thanks for your kindly.