Look at the picture.

The figure on the left shows the individual box colliders in green.

The yellow boxes on the right are the results of the optimization of the original box colliders.

What is the algorithm that makes this possible?

enter image description here


Sure you can.

Assuming you have a list of BoxCollider that need to be combined, you can access each of their bounds properties, which consist of the boxes' center and extents. With this two information in mind, you can easily calculate the minimum and maximum x, y, and z coordinates of the boxes.

The combined BoxCollider will have these two corners: and enter image description here. From upper and lower corners, you can calculate the center and extents of the combined BoxCollider.

All you need to do later is remove or disable initial BoxColliders in your list.

  • \$\begingroup\$ Can't you just manually edit the box colliders and make it bigger ? \$\endgroup\$
    – Shashimee
    Jul 13 '17 at 9:28
  • 1
    \$\begingroup\$ @Shashimee I believe the OP is asking for dynamically merging the colliders. Otherwise it's not called merging, it's simply resizing a collider. \$\endgroup\$
    – TomTsagk
    Sep 20 '19 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.