Dynamic Terrain and Physics Colliders

Thought I’d share something I was working on in my pet project:

I’m using a dynamic terrain that moves and generates with the camera. Since the terrain is always changing, I can’t use a single collider for the entire terrain (and even if I could, it would be too large and not performant).

Instead, I create a smaller, localized collider around the player’s current position. This collider is based on the vertices of the terrain within a certain diameter of the player.

To avoid the performance cost of creating and disposing the colliders every frame, I only update the colliders when the player approaches the edge of the current one they are on.

By adjusting the diameter of the collider and the threshold for creating a new one, I can control the balance between performance and how much of the scene is able to simulate physics.

In the video below, the first train car acts as the player that determines the collider position.

Let me know if you’d like more details on the implementation, and I can maybe clean up the code and make a proper blog post about it.

11 Likes

That´s really cool!!! hope to see more about this.

Would be awesome to see the code, implementation and test it out!

Would love to learn more about this approach!

Ok cool, I’ll make a post with the code! Will be interested in feedback, I’m not sure how this approach compares to chunking, but it was what came to me first.

Haven’t had a chance to do a proper write up, but here’s the code in the meantime: boxcar/src/systems/terrain/dynamicTerrainCollider.system.ts at main · ThomasBurgess2000/boxcar · GitHub

2 Likes