Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance issues with large static edges terrain in Box2D

I'd like to support very large worlds in the game that I'm making. This is not a problem usually, because I can cull most of the world as it is not visible all at once. However, Box2D doesn't seem to like my idea!

My terrain currently consists of about 1000 edge shapes. This alone seems to work fine, however: Even after I add only a few (~25) dynamic objects (small circles), the performance is decreasing dramatically!

  • Why does this happen, the dynamic tree should cancel out all unaffected static terrain shapes very early and without performance penalties, shouldn't it?
  • (How) can I work around this?
like image 643
Hero Avatar asked Nov 13 '22 23:11

Hero


1 Answers

The answer is because edge shapes do not collide with other edge shapes.

From the manual:

Edge shapes are line segments. These are provided to assist in making a free-form static environment for your game. A major limitation of edge shapes is that they can collide with circles and polygons but not with themselves. The collision algorithms used by Box2D require that at least one of two colliding shapes have volume. Edge shapes have no volume, so edge-edge collision is not possible.

So even though you have many edge shapes, as they do not collide with each other, you aren't seeing a performance drop. Once you add some objects, then box2d starts checking for collisions.

like image 114
Rahul Iyer Avatar answered Dec 09 '22 21:12

Rahul Iyer