Recap: Breakable Wall
Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 14 of 63.
Challenge
EasyA wall of ten bricks stands in front of a cannon. The ball is the cannonball (tagged Ball, script Cannon.cs, already written): the left and right arrows aim, Space fires. Every brick is a Rigidbody with a Brick script and a breakSpeed (6). Write Brick.cs:
- When the ball hits a brick at
breakSpeedm/s or faster, the brick breaks: logBrick brokenand destroy that brick. - Nothing else breaks a brick: not a slower ball, and not a brick that lands on the ground or on another brick, however fast it falls.
Press Play and knock the wall down, then Check.
Try it yourself
using UnityEngine;
public class Brick : MonoBehaviour
{
public float breakSpeed = 6f;
}
All lessons in Physics and Gameplay
1Rigidbody
Gravity and MassPush with AddForceJump with an ImpulseFixedUpdate for PhysicsVelocityKinematic BodiesRecap: Launch Pad2Collisions
OnCollisionEnterWhat Did I Hit?Break on ImpactStanding on the GroundBounce and FrictionCollider ShapesRecap: Breakable Wall