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 (ie 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?
我的猜测是你需要非线性阻尼,所以尝试在每帧上编辑线性阻尼值,并使用基于当前速度的公式。
尝试使用b2Body
线性阻尼参数:
body->SetLinearDamping(0.1f);
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! ^^
链接地址: http://www.djcxy.com/p/66160.html上一篇: 对象不移动时如何检测碰撞?
下一篇: 在没有重力的情况下放慢box2d中的物体