I am developing a small racing gam, 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 :
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)
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).
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.
Same as 2, but only put sections
N+1in physics engine (where
N= current section where the player is). When player reach section
N+1, unload section
Nand load section
N+2and 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 )
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.