Wich collider use to be optimize for map border

Hey everyody ! :smile:

I’m doing a 3D game on mobile, and I want to learn more about collider and optimization.

I have a litle 3D map for my level, and since few days, I was using big rock with mesh collider on it to limit the map.
To optimize it, I created in 3D with plane some border :

And I add it mesh collider too.
But I saw with some research that use “Mesh collider” is not recommended .
But how can I do ? I have to put dozens of box colliders? To be more optimized ?

If someone can explain me what to do i’ll really appreciate :smile:

Have a good day!

Mesh Collider is ok for this kind of collider. The Mesh Collider is good when used conveniently.

There’s no “one rule fits them all” that states whether some kind of collider is recommended or not. Each case has separate requirements and may use the available resources differently.

In your case, you can optimize your world limit collider by simply splitting it in smaller pieces and add a Mesh Collider to each piece, instead of using one single mesh collider for the entire limit. I’d split the collider in the picture in at least 10 pieces.

The physics engine uses the AABB (Axis Aligned Bounding Box) of each collider to determine if some other collider (i.e. the player collider) might be in contact with it. This is called “broad phase”, and allows to quickly discard the colliders that for sure won’t be in contact with the checked collider. Those colliders whose AABB overlap will be checked with more detail to find collisions. This is called “narrow phase”, and may involve checking collisions against each triangle of the involved colliders (costly).

From the above you can guess why splitting your large collider makes sense for optimizing collisions. If you use a single mesh collider then no matter where your player is, it will always fall inside the AABB of the world collider. The physics engine will put it into the narrow phase immediately, and may check for collisions against every triangle of the world collider.

On the other hand, if your world collider is split in several smaller pieces, then the physics engine can discard a lot of them quickly in the broad phase. It may even discard all them if the player is in the middle area. When the player approaches the world limits then only one or two of the smaller mesh colliders may enter the narrow phase, so detailed collisions are checked against those colliders only.

7 Likes

Wow, This explaination is perfect ! Thanks to you for your time , I understand now how it’s working :smile:!!

I will split them into multiple piece like you tell to me :slight_smile:

Wish you a great day sir !

1 Like