在无重力的情况下减慢 box2d 中的物体速度

发布于 2024-12-27 17:58:44 字数 286 浏览 0 评论 0原文

我正在制作台球游戏,因此我的重力设置为零,并且我施加脉冲来使母球移动。因为没有重力,所以我使用线性和角度阻尼来减慢球的速度。

虽然球有一定的速度,但它们实际上会减慢速度。问题就出现在它们减速很多并且即将停止但实际上没有停止 4-5 秒的时候,这看起来非常不现实。

我想到的解决方案之一是检查每一帧球的速度,如果它低于某个数字(即当球即将停止时),请将其设置为零以停止物体。这种方法的问题在于,我正在制作一款多人游戏,其中两个玩家的帧速率可能略有不同,从而使同一镜头的两次模拟不一致。

有人能想到其他解决方案吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

温柔女人霸气范 2025-01-03 17:58:44

我的猜测是您需要非线性阻尼,因此尝试使用基于当前速度的公式编辑每一帧的线性阻尼值。

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.

宁愿没拥抱 2025-01-03 17:58:44

尝试使用b2Body的线性阻尼参数:

body->SetLinearDamping(0.1f);

Try to use linear damping parameter of b2Body:

body->SetLinearDamping(0.1f);
心清如水 2025-01-03 17:58:44

如果您正在制作多人游戏,则需要裁判来确保不存在不一致的情况。两个客户端都连接到的服务器或一个(或两个)客户端都可以是主机。

重要的是,每个镜头在展示之前都会经过计算并发送给双方。由于台球是回合制的。每个客户端都可以托管自己的镜头并将结果发送到对手的游戏实例中“重播”。此外,这意味着延迟不应该成为太大的问题,因此您可以逐帧发送球位置(尽管这不是最佳的,但它是最容易实现的)。

如果您想要一些可以用于连接而无需费力设置服务器的东西,请查看 pubnub (http://www.pubnub.com/)。帐户设置和开发是免费的,并且设置相对容易。

希望这有帮助! ^^

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! ^^

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文