0
0
Unityframework~10 mins

Collider2D types (box, circle, polygon) in Unity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Collider2D types (box, circle, polygon)
Start: Choose Collider2D Type
Box
Set Size
Apply Collider to GameObject
Physics Interaction
End
Choose a Collider2D type, set its shape parameters, apply it to a GameObject, then it interacts with physics.
Execution Sample
Unity
var box = gameObject.AddComponent<BoxCollider2D>();
box.size = new Vector2(2, 3);

var circle = gameObject.AddComponent<CircleCollider2D>();
circle.radius = 1.5f;

var polygon = gameObject.AddComponent<PolygonCollider2D>();
polygon.points = new Vector2[] { new Vector2(0,0), new Vector2(1,0), new Vector2(0,1) };
This code adds three different Collider2D types to a GameObject and sets their shape sizes.
Execution Table
StepActionCollider TypeProperty SetValueResult
1Add BoxCollider2DBoxsizedefault (1,1)Box collider added with default size
2Set Box sizeBoxsize(2,3)Box collider size updated to (2,3)
3Add CircleCollider2DCircleradiusdefault 0.5Circle collider added with default radius
4Set Circle radiusCircleradius1.5Circle collider radius updated to 1.5
5Add PolygonCollider2DPolygonpointsdefault []Polygon collider added with default points
6Set Polygon pointsPolygonpoints[(0,0),(1,0),(0,1)]Polygon collider points updated
7Physics InteractionAllN/AN/AColliders interact with physics engine
8ExitN/AN/AN/ASetup complete, colliders ready
💡 All colliders added and configured, physics engine uses them for collision detection
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5After Step 6Final
box.sizeN/A(1,1)(2,3)(2,3)(2,3)(2,3)(2,3)(2,3)
circle.radiusN/AN/AN/A0.51.51.51.51.5
polygon.pointsN/AN/AN/AN/AN/A[][(0,0),(1,0),(0,1)][(0,0),(1,0),(0,1)]
Key Moments - 3 Insights
Why do we need to set size or radius after adding a collider?
By default, colliders have preset sizes (like 1x1 for box or 0.5 radius for circle). Setting size or radius changes the shape to fit your object, as shown in steps 2 and 4 of the execution_table.
Can a GameObject have multiple Collider2D types at once?
Yes, as shown in steps 1, 3, and 5, you can add multiple colliders to the same GameObject to combine shapes for complex collision areas.
What does setting polygon points do?
It defines the exact shape of the polygon collider by specifying its vertices, as seen in step 6 where points are set to form a triangle.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 4. What is the circle collider's radius after this step?
A1.5
B0.5
C2
DNot set yet
💡 Hint
Check the 'Value' column at step 4 in the execution_table.
At which step does the polygon collider get its points updated to a triangle shape?
AStep 5
BStep 3
CStep 6
DStep 2
💡 Hint
Look for 'Set Polygon points' action in the execution_table.
If you skip setting the box collider size after adding it, what size will it have?
ASize (2,3)
BDefault size (1,1)
CZero size
DNo collider created
💡 Hint
Refer to step 1 and 2 in the execution_table to see default and updated sizes.
Concept Snapshot
Collider2D types in Unity:
- BoxCollider2D: rectangle shape, set size with 'size'
- CircleCollider2D: round shape, set radius with 'radius'
- PolygonCollider2D: custom shape, set points array
Add collider to GameObject, then adjust shape properties
Used for 2D physics collision detection
Full Transcript
This visual execution shows how to add and configure three types of Collider2D components in Unity: BoxCollider2D, CircleCollider2D, and PolygonCollider2D. First, each collider is added to a GameObject with default shape sizes. Then, their shape properties are set: size for box, radius for circle, and points for polygon. The variable tracker shows how these properties change step-by-step. Key moments clarify why setting these properties is important and that multiple colliders can coexist on one object. The quiz tests understanding of property values at specific steps. This helps beginners see exactly how colliders are created and customized for 2D physics.