Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slowing down objects in box2d with no gravity

I am making a billiards game, so my gravity is set to zero and I apply impulse to make a cue ball move. Because there is no gravity, I use both, linear and angular damping to slow the balls down.

While the balls have some decent velocity, they slow down realistically. The problem start’s when they slowdown a lot and are about to stop but don’t actually stop for like 4-5 seconds, and that’s look’s very unrealistic.

One of the solutions that I thought was to check every frame the velocity of the ball and if it’s bellow some number (i.e. when the ball is about to stop), make it zero to stop the object. The problem with this approach is that I am making a multiplayer game, where two players can have a slightly different frame rate and thus making two simulations of the same shot inconsistent.

Can anyone think of any other solution?

like image 224
Alex Avatar asked Jan 19 '12 23:01

Alex


3 Answers

My guess is that you need non linear damping, so try to edit the linear damping value on every frame, with a formula based on the current speed.

like image 146
Rui Campos Avatar answered Sep 28 '22 06:09

Rui Campos


Try to use linear damping parameter of b2Body:

body->SetLinearDamping(0.1f);
like image 39
Andrew Avatar answered Sep 28 '22 07:09

Andrew


If you are making a multi-player game you need a referee to make sure that there are no inconsistencies. Either a server that both clients connect to or one (or both) of the clients can be the host.

The important thing is that each shot is calculated and sent to both parties before it is shown. Since billiards is turn based. Each client can host their own shot and sent the result to be "replayed" in the opponents game instance. Also this means that latency shouldn't be too much of an issue so you can send frame by frame ball positions (although this is not optimal, it is the easiest to implement).

If you want something that you can use for connection without the hastle of setting up a server have a look at pubnub (http://www.pubnub.com/). Account set-up and development is free and it's relatively easy to set up.

Hope this helps! ^^

like image 31
Goran Avatar answered Sep 28 '22 06:09

Goran