2D physics engine for Go? Where did Box2D go?

1,998 views
Skip to first unread message

zachary...@gmail.com

unread,
Jan 6, 2016, 4:49:16 PM1/6/16
to golang-nuts
I'm working on a little game server with Go and I've started thinking about implementing a 2D physics engine. When I looked around the only engines I could find were Chipmunk and Box2D-Lite. I implemented Chipmunk but it is sort of glitchy and doesn't seem to work very well.

I then started looking for a full Box 2D port but it seems like someone made it but then removed it:(

Has anyone else implemented 2D (or 3D) physics in Go? What is the best option for this?

Egon

unread,
Jan 7, 2016, 2:15:07 AM1/7/16
to golang-nuts, zachary...@gmail.com
Start with http://gafferongames.com/game-physics/ and there are plenty more:

Chipmunk and Box2D are full featured and complicated, with games you often can get by with much less effort. 

The cleanest code I've seen was in https://github.com/RandyGaul/ImpulseEngine, however you need to do some work to untangle some of the implementation. He also seems to have written a 3D engine https://github.com/RandyGaul/qu3e, since I last viewed.

+ Egon

zachary...@gmail.com

unread,
Jan 10, 2016, 12:37:18 PM1/10/16
to golang-nuts, zachary...@gmail.com
We decided that it would be more efficient to have the clients run the physics simulations, but thanks for the links to all of the physics engines! If I'm ever looking to implement physics in Go again I'll come back to this:) 

Egon

unread,
Jan 10, 2016, 1:27:01 PM1/10/16
to golang-nuts, zachary...@gmail.com
On Sunday, 10 January 2016 19:37:18 UTC+2, zachary...@gmail.com wrote:
We decided that it would be more efficient to have the clients run the physics simulations, but thanks for the links to all of the physics engines! If I'm ever looking to implement physics in Go again I'll come back to this:) 

Peer-to-peer engines are more difficult, than a dedicated server. Of course you can make one client the master.


+ Egon

zachary...@gmail.com

unread,
Jan 10, 2016, 3:55:42 PM1/10/16
to golang-nuts, zachary...@gmail.com
I think we are going to use a dedicated server but just have all of the physics logic done client side but all of the map logic done on the server.

Egon

unread,
Jan 11, 2016, 3:05:08 AM1/11/16
to golang-nuts, zachary...@gmail.com
On Sunday, 10 January 2016 22:55:42 UTC+2, zachary...@gmail.com wrote:
I think we are going to use a dedicated server but just have all of the physics logic done client side but all of the map logic done on the server.

I'm not quite following what kind of game you are exactly, but ...

If the physics have an effect (i.e. not just for visuals), someone will try to hack it. You also might need state-synchronization between clients, because of butterfly effects, and if you don't have a master chosen, then it becomes even more difficult. i.e. you must somehow come to a consensus, what really happened in the physics world.

In some games these can be problem, in others, not that much. There's no easy solution either way.

+ Egon

zachary...@gmail.com

unread,
Jan 11, 2016, 5:10:28 AM1/11/16
to golang-nuts, zachary...@gmail.com
Yeah I'm sort of worried about hacking, but the game should be pretty casual so there shouldn't be too much incentive to hack. But we all know someone will end up wanting to for some reason lol.

I just set up the server and it's working pretty well so I'll try to explain it better. Player 1 will send their position to the server, the server then stores that position and sends it to anyone else who is connected. Player 2 who is connected, is receiving Player 1's position and it is displayed on his/her game. The display is an actual GameObject with physics (I am using Unity) so Player 2 can still collide with Player 1 and what not. 

I know this is somewhat of a bad way to do this because, like you said, it's pretty easily hacked. Although Unity is sort of annoying to hack, it would be super easy for someone to just intercept the packets and send whatever they want. I'm thinking that once this becomes an issue I'll just check on the server for suspicious activity, like people teleporting, moving faster than normal, etc.

Egon

unread,
Jan 11, 2016, 5:23:52 AM1/11/16
to golang-nuts, zachary...@gmail.com


On Monday, 11 January 2016 12:10:28 UTC+2, zachary...@gmail.com wrote:
Yeah I'm sort of worried about hacking, but the game should be pretty casual so there shouldn't be too much incentive to hack. But we all know someone will end up wanting to for some reason lol.

I just set up the server and it's working pretty well so I'll try to explain it better. Player 1 will send their position to the server, the server then stores that position and sends it to anyone else who is connected. Player 2 who is connected, is receiving Player 1's position and it is displayed on his/her game. The display is an actual GameObject with physics (I am using Unity) so Player 2 can still collide with Player 1 and what not. 

Warning: Unity's physics engine is not deterministic. See what can happen https://www.youtube.com/watch?v=fR71d3u899Q, if you don't properly account for it.


That thread links to http://forum.unity3d.com/threads/dphysics-deterministic-2d-physics-engine.315553/, which might solve some of your issues. But, I have no clue how good it is.

zachary...@gmail.com

unread,
Jan 11, 2016, 2:37:24 PM1/11/16
to golang-nuts, zachary...@gmail.com
Woah I didn't know that at all thanks for showing me! I guess I'm going to have to account for this but I feel like using a completely separate physics engine might be over kill :/  Maybe I'll track more information on the server to make sure all of the objects are in the same place for everyone

Egon

unread,
Jan 12, 2016, 2:07:01 AM1/12/16
to golang-nuts, zachary...@gmail.com


On Monday, 11 January 2016 21:37:24 UTC+2, zachary...@gmail.com wrote:
Woah I didn't know that at all thanks for showing me! I guess I'm going to have to account for this but I feel like using a completely separate physics engine might be over kill :/  Maybe I'll track more information on the server to make sure all of the objects are in the same place for everyone

And what will you do when they are not?
You can easily end up with two problems, popping and/or terrible lag.

Here's a suggestion, before moving forward, go read all Gaffer's posts. I.e. Game Physics, Game Networking, Virtual Go, Networked Physics etc. If you ignore all the equations, then it should be a very quick read. However, it will show all of these problems I mentioned and save you a lot of time in the end.

http://gafferongames.com/ (everything on the right side)

+ Egon

Egon

unread,
Jan 12, 2016, 2:08:24 AM1/12/16
to golang-nuts, zachary...@gmail.com
On Tuesday, 12 January 2016 09:07:01 UTC+2, Egon wrote:


On Monday, 11 January 2016 21:37:24 UTC+2, zachary...@gmail.com wrote:
Woah I didn't know that at all thanks for showing me! I guess I'm going to have to account for this but I feel like using a completely separate physics engine might be over kill :/  Maybe I'll track more information on the server to make sure all of the objects are in the same place for everyone

And what will you do when they are not?
You can easily end up with two problems, popping and/or terrible lag.

Here's a suggestion, before moving forward, go read all Gaffer's posts. I.e. Game Physics, Game Networking, Virtual Go, Networked Physics etc. If you ignore all the equations, then it should be a very quick read. However, it will show all of these problems I mentioned and save you a lot of time in the end.

http://gafferongames.com/ (everything on the right side)

// Also read comments on each article.
Reply all
Reply to author
Forward
0 new messages