Unity - Custom Collision Boundaries


Advertisements

In this chapter, let us learn about custom collision boundaries. We will also learn how to adjust the size and shape of our colliders.

Let us start with our Box Collider. The Box Collider (2D) has 4 adjustable sides, and is shaped like a rectangle. In the Collider’s component, click on this box −

Box Collider (2D)

You will see 4 “handles” show up on the collider. You can drag these handles around to adjust their sizes.

4 Handles

For simple shapes, Unity detects the best possible fit for the collider’s shape as well, provided you pick the right one. For example, picking the circle collider on a circle sprite will match it to its radius.

circle sprite

For more complex shapes, Unity will try to create the simplest yet most elaborate collider shape. For that, you need to use the Polygon Collider 2D.

Polygon Collider 2D

Try to click on the Edit Collider button and experiment on adjusting the colliders.

Advertisements