With revision 33, really easy to tunnel through line shapes.

Submitted this to google code:

http://code.google.com/p/box2d/issues/detail?id=71

Just posting this here as a warning to others. Anyone else noticing this behavior?
Continuous collision is now done sequentially: kinematic bodies are moved first, then non-bullet dynamic bodies, then bullet dynamic bodies. If a kinematic body moves over a dynamic body, you may get tunneling. Similarly, bullets are handled last, so if a dynamic body moves over the bullet, then the bullet may tunnel through the dynamic body.

I know this sounds like a step backwards, but it is not. Before you could setup scenarios where a dynamic body could tunnel through a static body. Dynamic vs static tunnel prevention is the top priority of the system.

Let me know if you see any dynamic vs static tunneling and please provide an example.
Erin Catto wrote:
I know this sounds like a step backwards, but it is not. Before you could setup scenarios where a dynamic body could tunnel through a static body. Dynamic vs static tunnel prevention is the top priority of the system.

How?

I'm not really understanding the new code, though it's very late for me. You don't seem to be advancing both bodies to the same time before re-evaluating contacts any more. How can that ever give a useful result? And bodies can only Advance once per step?
Static bodies don't move. So sequential resolution works fine for dynamic vs static.

Since no other open source physics engine has functional continuous simulation, we have a limited knowledge base in this area. As others have noted, there is almost no literature on the topic. There are many articles on continuous collision detection (CCD). Box2D does well in this respect. The Box2D time of impact (TOI) algorithm handles fast rotation of slender bodies quickly and robustly. The open problem is continuous simulation. How do we combine CCD, integration, and constraint solvers to prevent tunneling? It is not enough to just capture the TOI, we have to prevent further approach without hitting a deadlock. I have been working on this problem for awhile now. It is one of the most challenging problems in rigid body physics simulation.

So I think we need to make small steps in this area. In retrospect, I believe I was too ambitious with the initial feature set.

I tried to retain support for bullets, and they work well in many cases. They will not tunnel through static bodies, but they may tunnel through kinematic and dynamic bodies in some cases. In those cases, both bodies are probably moving fast. Bullets should work okay versus slow moving bodies.

The previous system depended on the contact solver giving an accurate result during sub-steps, but it cannot because it uses an iterative solver (for performance). So while the previous system had more capabilities, it was not as robust as I desired. So I had to sacrifice some features to improve robustness. Which should we value more? In my opinion if a feature is not robust, it should either be fixed or removed. I could not determine how to make sub-stepping robust, so I removed the feature. You could argue the new system is not robust because bullets can sometimes tunnel through kinematic and dynamic bodies, but I argue that this is a known limitation, so the feature is robust. In the previous system, dynamic bodies could sometimes tunnel through static bodies, but that was not a stated or designed limitation.
Here's a demo that illustrates the issue (It's flash - but it's the C++ version running):

http://www.sideroller.com/tunnel.swf

It is really easy to get the balls through the kinematic line shapes. It is also possible to get the balls through the static shapes, but a bit harder. The balls also seem to freak out and "float" when you try to pull them through the areas of high-detail geometry.

I understand the need for simplification and if there are certain limitations we'll have to live with. It's just weird to see something break that worked fine before.

If these changes mean greater speed, then I'm absolutely willing to abandon kinematic line shapes...
I was asking how the old system was broken wrt to tunnelling dynamic bodies through static ones. I didn't see any reports of it. Or is this to do with fast rotation?

Would I be right in saying that if a dynamic body was shot at a wall made of small, fast kinematic bodies, it would be unable to get through, but equally it wouldn't register a collision with anything.

Can bullets tunnel through other bullets? It looks to me if they can, even without rotation and if one body is stationary. That seems fairly problematic - bullets were nice because you could increase the amount of CCD in use by turning on more and more bullets. I guess now they are just good for literal bullets.

OTOH, it looks plausible that the new system can be done in a somewhat parallel fashion, which is cool.
mayobutter wrote:
http://www.sideroller.com/tunnel.swf


I just uploaded a new test called EdgeShapes. It doesn't show any of the problems that the SWF demo has. Please try to reproduce your problem in the C++ testbed.

This was one of the bugs with the old system:
http://code.google.com/p/box2d/issues/detail?id=49

The problem wasn't specifically fast rotations. The problem was trying to solve islands in the sub-step. It would lead to tunneling when unfavorable forces, geometry, or mass ratios were involved. The old TOI code also allowed shapes to get closer and closer until it gave up. This made it incredibly difficult to debug because tunneling was the result of several accumulated inaccuracies.

The new system is much more focused. I have a single moving body that I'm trying to solve. I don't have to worry about the effects of other moving bodies or joints. The new system is trivial to parallelize in the non-bullet case. Performance should also be improved.

BorisTheBrave wrote:
Would I be right in saying that if a dynamic body was shot at a wall made of small, fast kinematic bodies, it would be unable to get through, but equally it wouldn't register a collision with anything.


If both bodies are moving fast, you can get tunneling.

BorisTheBrave wrote:
Can bullets tunnel through other bullets? It looks to me if they can, even without rotation and if one body is stationary. That seems fairly problematic - bullets were nice because you could increase the amount of CCD in use by turning on more and more bullets. I guess now they are just good for literal bullets.


Fast moving bullets should not tunnel through any slow moving bodies. I do want bullets to be used for fast vs slow. For now, I'm giving up on fast vs fast. I never saw a big importance for fast vs fast.

BorisTheBrave wrote:
OTOH, it looks plausible that the new system can be done in a somewhat parallel fashion, which is cool.


Yes, the old sub-stepping approach would likely become a bottleneck in a multi-threaded implementation.
Erin Catto wrote:
Fast moving bullets should not tunnel through any slow moving bodies. I do want bullets to be used for fast vs slow.

The case I was thinking of: If both bodies are bullets, one fast and one slow, such that without CCD they'd tunnel. Then if the fast one has SolveTOI evaluated before the slow one (as they are both bullets), then the contact between them won't be considered at that time, causing the fast body to be advanced past where it would otherwise hit.
BorisTheBrave wrote:
Erin Catto wrote:
Fast moving bullets should not tunnel through any slow moving bodies. I do want bullets to be used for fast vs slow.

The case I was thinking of: If both bodies are bullets, one fast and one slow, such that without CCD they'd tunnel. Then if the fast one has SolveTOI evaluated before the slow one (as they are both bullets), then the contact between them won't be considered at that time, causing the fast body to be advanced past where it would otherwise hit.


Let the slow body have positions P1 and P2 at the beginning and end of the time step. If position P1 and P2 both obstruct the path of the fast bullet, then you will get a TOI event. If P1 or P2, but not both, obstruct the path of the fast body, then it is possible to miss the collision, based on the ordering of the TOI solve.
Yeah, exactly.

Original thread: https://box2d.org/forum/viewtopic.php?t=4357