在 Box2d、AndEngine 中,快速移动的物体有时会错过碰撞

发布于 2024-12-18 15:41:43 字数 112 浏览 3 评论 0原文

我有一个动态的快速移动身体(A)。它应该与另一个物体(B)碰撞。 A 与 B 发生碰撞,但有时它会经过 Body B 而不会发生碰撞。这完全是随机行为。我一定会遇到那种碰撞。请指导为什么它会随机出现这样的行为。

I have a Fast Moving Body(A) which is dynamic. It is supposed to collide with another Body(B). A collides with B, but sometimes it passes the Body B without collision. This is totally random behavior. I must have that collision. Kindly guide why it is acting like this, randomly.

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

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

发布评论

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

评论(1

梦断已成空 2024-12-25 15:41:43

由于单个时间步长内的较大运动而导致一个对象穿过另一个对象的效应称为隧道效应

Box2D 在动态和静态对象之间使用连续碰撞检测来解决此问题。但是,您的情况(动态与动态)不会自动处理,因此您的对象在评估碰撞时是否恰好处于碰撞位置只是随机掷骰子。

来自 Box2d 手册

通常动态物体之间不使用 CCD。这样做是为了保持
性能合理。在某些游戏场景中你需要动态物体
使用CCD。例如,您可能想要发射高速子弹
一堆动态砖块。如果没有 CCD,子弹可能会打洞
穿过砖块。

Box2D 中快速移动的物体可以标记为子弹。子弹会
使用静态和动态物体执行 CCD。你应该决定
根据您的游戏设计,哪些物体应该是子弹。如果你决定
主体应被视为子弹,请使用以下设置。

bodyDef.bullet = true;

子弹标志仅影响动态物体。

Box2D按顺序进行连续碰撞,因此子弹可能会错过
快速移动的物体。

The effect of one object passing through another due to large movement in a single timestep is called tunneling.

Box2D uses Continuous Collision Detection between dynamic and static objects to solve this problem. However, your case (dynamic v.s. dynamic) isn't automatically handled, so it's just a random dice throw whether your objects happen to be in colliding positions at the exact moment the collisions are evaluated.

From the Box2d Manual:

Normally CCD is not used between dynamic bodies. This is done to keep
performance reasonable. In some game scenarios you need dynamic bodies
to use CCD. For example, you may want to shoot a high speed bullet at
a stack of dynamic bricks. Without CCD, the bullet might tunnel
through the bricks.

Fast moving objects in Box2D can be labeled as bullets. Bullets will
perform CCD with both static and dynamic bodies. You should decide
what bodies should be bullets based on your game design. If you decide
a body should be treated as a bullet, use the following setting.

bodyDef.bullet = true;

The bullet flag only affects dynamic bodies.

Box2D performs continuous collision sequentially, so bullets may miss
fast moving bodies.

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