What is the best way to implement collision detection using Bullet physics engine and a track generated from a curve?

Posted by tigrou on Game Development See other posts from Game Development or by tigrou
Published on 2012-11-05T16:30:36Z Indexed on 2012/11/05 17:20 UTC
Read the original article Hit count: 233

I am developing a small racing game were the track is generated from a curve.

As said above, the track is generated, but not infinite. The track of one level could fit with no problem in memory and will contain a reasonably small amount of triangles.

For collisions, I would like to use Bullet physics engine and know what is the best way to handle collisions with the track efficiently.

NOTE : The track will be stored as a static rigid body (mass = 0). The player will be represented by a sphere shape for collisions.

Here is some possibilities i have in mind :

  1. Create one rigid body, then, put all triangles of the track (except non collidable stuff) into it. Result : 1 body with many triangles (eg : 30000 triangles)

  2. Split the track into several sections (eg: 10 sections). Then, for each section, create a rigid body and put corresponding triangles in it. Result : small amount of bodies with relatively small amount of triangles (eg : 1500 triangles per section).

  3. Split the track into many sub-sections (eg : 1200 sections). Here one subsection = very small step when generating the curve. Again for each sub-section, create a body and put triangles in it. Result : many bodies with very small amount of triangles (eg : 20 triangles). Advantage : it could be possible to "extra data" to each of the subsection, that could be used when handling collisions.

  4. Same as 2, but only put sections N and N+1 in physics engine (where N = current section where the player is). When player reach section N+1, unload section N and load section N+2 and so on... Issue : harder to implement, problems if the player suddenly "jump" from one section to another (eg : player fly away from section N, and fall on section N + 4 that was underneath : no collision handled, player will fall into void )

  5. Same as 4, but with many sub-sections. Issues : since subsections are very small there will be constantly new bodies added and removed to physics engine at runtime. Possibilities for player to accidently skip some sections and fall into the void are higher than 4.

© Game Development or respective owner

Related posts about 3d

Related posts about collision-detection