Part 4 — Add walls and colliders
In this part, we will add the first objects the ball can bounce against: the left, right, and top walls.
We are still not building the whole level. We are creating just enough of the playfield to learn how colliders and rigidbodies interact.
Create a Boundaries Parent
Create an empty GameObject called Boundaries.
This parent is only for organization. It does not need a renderer, collider, or script.
Add the Top Wall
Under Boundaries, create a thin rectangle and rename it North Wall.
Place it above the ball near the top of the visible play area.
Add or confirm these components:
Rectangle Renderer, so you can see it while buildingBoxCollider2D, so the ball can collide with it
The wall does not need a Rigidbody2D. A collider without a rigidbody behaves like a static collider: it stays still and other physics bodies can collide with it.
Press Play. The ball should move until it hits the wall, then respond to the collision.
Add the Side Walls
Duplicate North Wall twice and rename the duplicates:
West Wall
East Wall
Move them to the left and right edges of the play area. Rotate or resize them so each wall is tall and thin.
Press Play again and confirm the ball can collide with the walls.
Use the Bouncy Material
Select the ball collider and assign the BouncyMaterial2D physics material you created earlier.
For Breakout, the material should have high restitution and low friction. Restitution controls how much bounce the ball keeps after a collision. Friction controls how much the contact tries to slow or drag movement along the surface.
Tip: If the ball loses too much speed after collisions, check the physics material first. Breakout needs a lively ball.
Understand Body Types
You have now used two different physics roles:
- the ball is
Dynamic, because physics moves it - the walls are static colliders, because they stay still and do not need a rigidbody
Later, the paddle will use a Kinematic rigidbody. Kinematic bodies are useful for objects you move intentionally from code while still letting other objects collide with them.
Continuous vs Discrete Collision
If a fast object passes through a thin wall, it may be moving too far between physics checks.
Use this rule of thumb:
Discreteis fine for slow or thick objects.Continuousis safer for fast objects like the ball.
If you notice tunneling while testing, set the ball's collision detection to Continuous.
Checkpoint
At the end of this part, you should have:
- a
Boundariesparent North Wall,West Wall, andEast Wall- a
BoxCollider2Don each wall - a bouncy physics material assigned to the ball collider
- a ball that collides with the walls during Play mode
Next, we will move the paddle with physics.