Problem with tunneling between dynamic and static bodies

Our iOS game uses Box2D to simulate a motorbike, which is built from Circle and Polygon shapes combined with Wheel and Revolute joints. We also have a rider on top of the bike who is comprised of Polygon shapes and Revolute joints.

Our terrain is one very large b2ChainShape making a chain.

We are having issues with our motorbike tunneling through the terrain at specific points at certain speeds.

When running 2.2.1 or 2.3.0 (actually r241 from SVN) there is one point on the terrain we have noticed where at a high enough speed the bike will fall through as depicted in this GIF animation:

Image

Note that the two skinny "arms" connected to the wheels and the "engine block" (as we call it) that the rear arm is attached to all have their filter maskBits set to 0, so don't collide with the terrain. I did this because before then we were having even more issues with collisions with the terrain.

All the bodies on the bike and rider are set to be bullets, so I would expect the CCD to be preventing this kind of tunneling?

We have found that this problem spot has no issues whatsoever with 2.2.0 and using a b2LoopShape instead of a b2ChainShape (which b2LoopShape was changed to in 2.2.1). See this animation where it successfully recovers from the landing (exact same conditions, no human input):

Image

Unfortunately 2.2.0 breaks in other ways on other parts of the track, there is one area where simply driving up the incline at a specific place causes the bike to crush into the terrain. I have an animation of this too, however finding the right conditions to make this repeatable was extremely difficult as it did not seem to happen every time I ran the simulation. It seems that only certain speeds trigger this complete failure, at other times the bike is momentarily caught on an invisible force but recovers without collapsing into the terrain.

This animation shows the failure while driving up the incline:

Image

Note that this failure does not occur in 2.2.1 or 2.3.0. We did get a similar failure very regularly with 2.2.1 earlier until we realised that our terrain was including the same adjacent vertices twice, once removed the simulation became far more stable - but still has problems like this.

These problems appear at only specific points on the terrain, the rest of the terrain functions perfectly - anecdotally even smoother in 2.2.1+

Some other details about our setup:

  • Box2D is run with a fixed timestep of 1/60th of a second (I also tried it with 1/120th of a second, but the problem still occurred - perhaps less often).
  • We are using 8 velocity iterations and 8 position iterations.

Any suggestions for what might be going wrong here?
The chain shape has some new code to make collisions smooth, especially for boxes sliding across vertices. There might be a bug in that. I would be happy to look at the problem if you can dump a portion of the world with b2World::Dump. You could also try disabling the connectivity (make a bunch of edge shapes).
Thanks for the reply Erin, I'm looking into producing a dump file now.

Do you mind clarifying what you mean by "try disabling the connectivity (make a bunch of edge shapes)" ? I'm not familiar with how b2EdgeShape should be used. Would I create a b2EdgeShape for every edge between two points? That's a lot of shapes, there would be no performance impact from this?
Ok I've managed to get a dump and loaded it into the TestBed to verify that the problem occurs there. The example drops the bike from a hight high enough to trigger the problem.

Note that I had to change:
Code:
settings.viewCenter.Set(0.0f, 20.0f);
to:
Code:
settings.viewCenter.Set(2400.0f, 20.0f);
in Main.cpp to get the world to appear on screen on launch.

The dump file is attached to this post.
Ok I've tried converting the terrain to b2EdgeShapes (with ghost vertices) and the tunneling still occurs 🙁
I reproduced this and can see the problem. I should be able to give you a fix soon.
Awesome! Thank you so much for your help, and Box2D itself! Very appreciative.
I was worried about the long distance from the origin. This still might cause some trouble. However, I shifted all the vertices by (-2400,0) and found that the problem is due to vertex 21 and 22 being very close together. Eliminating vertex 21 solved the tunneling problem for me.

Code:
-      vs,45   0x000000000030e5e0 {x=-49.641113 y=-9.0000000 }   b2Vec2 [45]
+      [0]   {x=-49.641113 y=-9.0000000 }   b2Vec2
+      [1]   {x=-49.641113 y=3.5837979 }   b2Vec2
+      [2]   {x=-47.868164 y=4.8466425 }   b2Vec2
+      [3]   {x=-46.756836 y=5.7763190 }   b2Vec2
+      [4]   {x=-45.729980 y=6.7755480 }   b2Vec2
+      [5]   {x=-45.256104 y=7.3010640 }   b2Vec2
+      [6]   {x=-44.812500 y=7.8437519 }   b2Vec2
+      [7]   {x=-44.812500 y=7.8437500 }   b2Vec2
+      [8]   {x=-44.291016 y=8.4996624 }   b2Vec2
+      [9]   {x=-43.732422 y=8.9999456 }   b2Vec2
+      [10]   {x=-43.128906 y=9.3596745 }   b2Vec2
+      [11]   {x=-42.471924 y=9.5939178 }   b2Vec2
+      [12]   {x=-41.753662 y=9.7177496 }   b2Vec2
+      [13]   {x=-40.965332 y=9.7462416 }   b2Vec2
+      [14]   {x=-40.097656 y=9.6944666 }   b2Vec2
+      [15]   {x=-31.119629 y=8.3505783 }   b2Vec2
+      [16]   {x=-27.368652 y=8.1033020 }   b2Vec2
+      [17]   {x=-22.966797 y=8.1378345 }   b2Vec2
+      [18]   {x=-17.847656 y=8.5747509 }   b2Vec2
+      [19]   {x=-11.943359 y=9.5346279 }   b2Vec2
+      [20]   {x=-5.1875000 y=11.138041 }   b2Vec2
+      [21]   {x=-1.4685059 y=12.218754 }   b2Vec2
+      [22]   {x=-1.4687500 y=12.218750 }   b2Vec2
+      [23]   {x=-0.87719727 y=12.236835 }   b2Vec2
+      [24]   {x=-0.28271484 y=12.037038 }   b2Vec2
+      [25]   {x=0.33276367 y=11.643272 }   b2Vec2
+      [26]   {x=0.98730469 y=11.079454 }   b2Vec2
+      [27]   {x=4.3569336 y=7.6019831 }   b2Vec2
+      [28]   {x=5.4782715 y=6.5466447 }   b2Vec2
+      [29]   {x=6.7465820 y=5.4647517 }   b2Vec2
+      [30]   {x=8.1813965 y=4.3802176 }   b2Vec2
+      [31]   {x=9.8000488 y=3.3169584 }   b2Vec2
+      [32]   {x=11.620117 y=2.2988939 }   b2Vec2
+      [33]   {x=13.660645 y=1.3499355 }   b2Vec2
+      [34]   {x=15.939453 y=0.49400043 }   b2Vec2
+      [35]   {x=18.474609 y=-0.24499416 }   b2Vec2
+      [36]   {x=21.283936 y=-0.84313202 }   b2Vec2
+      [37]   {x=24.385986 y=-1.2764969 }   b2Vec2
+      [38]   {x=27.798828 y=-1.5211754 }   b2Vec2
+      [39]   {x=31.540039 y=-1.5532494 }   b2Vec2
+      [40]   {x=35.628418 y=-1.3488026 }   b2Vec2
+      [41]   {x=40.081787 y=-0.88392067 }   b2Vec2
+      [42]   {x=44.918213 y=-0.13468552 }   b2Vec2
+      [43]   {x=50.155762 y=0.92281914 }   b2Vec2
+      [44]   {x=50.155762 y=-9.0000000 }   b2Vec2
Thanks Erin, removing the very close vertices did the trick 🙂
I'm having exactly same problem. Once I switched the terrain from separate (and pretty thick) static boxes to b2ChainShape, our test vehicle started getting stuck in the terrain

I don't have nice gifs to show the effect, but it looks like the very same problem

Just like at OP's case - car, wheels, axles etc are set as bullets, terrain is a static b2ChainShape (tried bulleting it as well, no change), pos & vel iterations are 8, timestep is fixed at 1/60

However - my verts are spaced quite far apart. I've printed the distances out - and they are no less than 2 meters (with standard PTM of 32) apart

Vehicle's speed isnt all that high, it's under 20 meters per second

I'm running version 2.2.2 of Box2d. EDIT: Downloaded 2.3.0 - same thing

Help will be greatly appreciated 🙂 Also - are you doing physics for D3 ?

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