简体   繁体   English

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

[英]Fast moving bodies miss the collision sometimes in Box2d, AndEngine

I have a Fast Moving Body(A) which is dynamic. 我有一个动态的快速移动体(A)。 It is supposed to collide with another Body(B). 它应该与另一个身体(B)发生碰撞。 A collides with B, but sometimes it passes the Body B without collision. A与B碰撞,但有时它会在没有碰撞的情况下通过B体。 This is totally random behavior. 这是完全随机的行为。 I must have that collision. 我必须有这种碰撞。 Kindly guide why it is acting like this, randomly. 请随意指导它为什么这样做。

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. Box2D使用动态和静态对象之间的连续碰撞检测来解决此问题。 However, your case (dynamic vs 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 : 来自Box2d手册

Normally CCD is not used between dynamic bodies. 通常情况下,动态物体之间不使用CCD。 This is done to keep performance reasonable. 这样做是为了保持合理的性能。 In some game scenarios you need dynamic bodies to use CCD. 在某些游戏场景中,您需要使用动态物体来使用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. 没有CCD,子弹可能穿过砖块。

Fast moving objects in Box2D can be labeled as bullets. Box2D中的快速移动物体可以标记为子弹。 Bullets will perform CCD with both static and dynamic bodies. 子弹将使用静态和动态物体执行CCD。 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; bodyDef.bullet = true;

The bullet flag only affects dynamic bodies. 子弹标志仅影响动态物体。

Box2D performs continuous collision sequentially, so bullets may miss fast moving bodies. Box2D按顺序执行连续碰撞,因此子弹可能会错过快速移动的物体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM