This project has moved and is read-only. For the latest updates, please go here.

Questions about polygon shapes

Topics: User Forum
Jun 9, 2012 at 12:45 PM


I'm building my side scrolling game's terrain with polygons, and I have a few questions:

1. Are many simple bodies better (faster) than fewer very complex ones? Should I stick to triangles or is it ok to make polygons with 16 corners? I know I can convert complex to a bunch of simpler ones, but is there need for it?

2. Are many smaller bodies better than few large ones? For example a long piece of flat ground.

3. What is the difference between Edges and filled Bodies? Recommendations?


Thanks :)

Jun 10, 2012 at 12:11 AM

In general static bodies have quite little overhead so in terms of performance probably we should only look at collisions.

It would seem pretty intuitive that "simpler" polygons (where by simple I mean lower amount of vertices) should be faster but actually the engine is quite advanced in that regard. You can look at Collision.cs and especially FindMaxSeparation(). In the end probably eveything will depend on the number of collisions. A standard platformer doesn't have that many collisions going on to make a difference. I have a scene with 300 bodies and 100 simulatneous collisions and I have found the need to keep the shapes as simple as possible but that's just a heuristic. 

Same reasoning for  question 2 - might be faster to have many small bodies but (big BUT) for the engine to find out the correct vertices of a large body is just a computation of a few dot products so the overhead of the small bodies could easily outweigh a theoretical benefit. I'm again speaking just from reading the code, haven't actually benchmarked anything.

3. Terrain made of polygons has  pretty nasty issue outlined very well in this thread on the Box2D forums: