Been wanting to do this for a while and now I had the algorithm to do it. Previously, each block would get it's own collider, creating a maximum of 1024 box colliders per level in a chunk. Now the box shapes are combined, creating fewer collisionshapes.
Slopes are separated from cubes. Slopes still have their own collision shapes and are not reduced in any way.
Blocks are merged horizontally over the x-axis. this creates long boxes of combined cubes
Blocks are merged over the z-axis if their start and end position match.
This algorithm works for our game because we often deal with flat terrain and houses on top of it. Houses have thin walls that are stretched either horizontally or vertically. I considered this when creating the algorithm. It should even work if the player starts digging round into the ground down the line.
It is essential to reduce the amount of colliders, because they can only be added to the scene on the main thread. This will cause strain on the physics server.
Here is an image with the colliders visualized:
If you look at the garage and the road, you can see there are few lines and big box collisionshapes.
Requires #253
Been wanting to do this for a while and now I had the algorithm to do it. Previously, each block would get it's own collider, creating a maximum of 1024 box colliders per level in a chunk. Now the box shapes are combined, creating fewer collisionshapes.
This algorithm works for our game because we often deal with flat terrain and houses on top of it. Houses have thin walls that are stretched either horizontally or vertically. I considered this when creating the algorithm. It should even work if the player starts digging round into the ground down the line.
It is essential to reduce the amount of colliders, because they can only be added to the scene on the main thread. This will cause strain on the physics server.
Here is an image with the colliders visualized:
If you look at the garage and the road, you can see there are few lines and big box collisionshapes.