In Unity, the physics behavior of an object is defined separately from its shape (mesh) and renderer (material). The Unity physics engine controls the positional and rotational forces that affect the transform of an object, such as gravity, friction, momentum, and collisions with other rigid bodies. The items that play into physics include:
- Rigidbody component
- Collider component
- Physic material
- Project Physics Manager
So, two things will be needed to make our ball bounce. It must have a Rigidbody component, so the Unity physics engine will know to apply forces to it. In particular, we want the ball to respond to gravity. Secondly, we will apply a physic material so the ball not only falls, but then bounces when it hits another object.
To add a Rigidbody:
- Select the Ball in Hierarchy, and Add Component | Rigid Body.
- Check its Use Gravity checkbox.
If you press Play now, you will see the ball drop like a brick. It hits the floor and just stops. Let's make it bouncy by applying a physics material (Unity spells it without the "s").
- In Project Assets/ARPlayBall/PhysicMaterial, create a new physic material (right-click Create | Physic Material).
- Name it BouncyBall.
- Set its Bounciness to 0.8.
- Set the Bounce Combine to Maximum.
- Drag the BouncyBall physic material onto the Ball's Sphere Collider's Material slot, as shown in the following screenshot:
Press Play now and the ball with bounce, slowly diminishing height, and eventually comes to a stop.