Menu
CoddyTech

Recap: Breakable Wall

Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 14 of 71.

This recap puts the chapter together: OnCollisionEnter, the tag of what hit you, and the impact speed from collision.relativeVelocity.

challenge icon

Challenge

Easy

Write Brick.cs: a fast cannonball breaks the brick it hits.

  1. In the brick's OnCollisionEnter, test collision.gameObject.CompareTag("Ball") and collision.relativeVelocity.magnitude >= breakSpeed together, with &&.
  2. When both are true, log Brick broken and Destroy(gameObject);. Slow balls and falling bricks break nothing.

Press Play, aim with the arrows and fire with Space. Then Check.

Try it yourself

using UnityEngine;

public class Brick : MonoBehaviour
{
    public float breakSpeed = 6f;
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Physics and Gameplay

Practice on your own: Unity playground