Irregular voxel terrain collisions #1067
-
Hi, I'm working on a low poly terrain and would like to add collisions between the terrain and the player capsule. In the example image, highlighted in red is a cell (a convex polyhedron) and so are the other ones delimited by the grey borders. Potentially, there can be many cells (which make up the terrain), from a few hundred up to 20-30 thousands. The MeshShape class seems well suited for modelling the terrain part. The problem is, the cells can be deleted, modified or new ones inserted and so changing the underlying triangles. What do you think? Would that work? Thank you for your thoughts. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The MeshShape really wasn't made to be updated at run time. I would probably divide the terrain in a regular grid and create a StaticCompoundShape per tile consisting of the polyhedrons (pick e.g. the center of mass of the shape to classify which tile it is in). StaticCompoundShapes are fairly cheap to create at run-time, so if the terrain changes you can create a new StaticCompoundShape for the affected tile. If the terrain changes very often, you can use a MutableCompoundShape instead of a StaticCompoundShape but then you're trading rebuild speed for query performance. The size of the grid is something to determine experimentally by profiling, you want a balance between the query cost (more shapes per tile is better) and rebuild time (less shapes per tile is better). |
Beta Was this translation helpful? Give feedback.
You mentioned that your shapes were 'a convex polyhedron' so I assumed that the terrain was built out of these shapes and that is what I proposed to put in the StaticCompoundShape.
If you want to do hidden surface removal then you would indeed need to create a MeshShape per cube, but then obviously you're creating (smaller) MeshShapes on the fly. I can't predict if that is going to be fast enough. Some effort was made to make the creation faster, but it was always meant to be an offline process as it tries to optimize the resulting shape for a balance between speed and memory usage and it bit packs all data in a single memory block.
Doing…