Fast moving bodies miss a collision sometimes in Box2d, AndEngine

I have a moving body (A) that is dynamic. He must collide with another body (B). A collides with B, but sometimes it passes through body B without collision. This is completely random behavior. I must have this collision. Please explain why this happens at random.

+4
source share
1 answer

The effect of one object passing through another due to large movement in one time interval is called tunneling .

Box2D uses continuous conflict detection between dynamic and static objects to solve this problem. However, your case (dynamic vs dynamic) is not handled automatically, so it’s just random throws that throw your objects into a collision of positions at the moment when the collisions are evaluated.

From Box2d Manual :

Typically, CCD is not used between dynamic bodies. This is done in order to be effective. In some game scenarios, you need dynamic bodies to use CCDs. For example, you might want to shoot a high-speed bullet onto a stack of dynamic bricks. Without a CCD, a bullet can tunnel through bricks.

Fast moving objects in Box2D can be marked as bullets. Bullets will perform CCDs with both fixed and dynamic bodies. You have to decide which bodies should be bullets based on your game design. If you decide the body should be considered as a bullet, use the following setting.

bodyDef.bullet = true;

The bullet flag affects only dynamic bodies.

Box2D sequentially performs a continuous collision, so bullets can miss fast-moving bodies.

+7
source

Source: https://habr.com/ru/post/1383587/


All Articles