Time for action – make the Ball bouncy

  1. Let's import a new package with certain goodies we'll need to make the Ball bounce. In the menu, navigate to Assets | Import Package | Physic Materials, then click on the Import button. A bunch of Physic Materials (whatever they are) get added to our Project panel:
    Time for action – make the Ball bouncy
  2. Make sure that the Ball is selected.
  3. In the Inspector panel, find the Sphere Collider component of the Ball. If it is closed, click on the gray triangular arrow to expand it so that you can get at its goodies.
  4. Find the Material parameter of the Sphere Collider.
  5. Click the small black circle next to the label that reads None (Physic Material).
  6. Double-click Bouncy from the list.
  7. Test your game by clicking on the Play button.
  8. When you finally snap out of it, press Play again to escape the mesmerizing results.
    Time for action – make the Ball bouncy

The Physic Materials package that we just imported includes a number of useful prebuilt physic materials. These special materials change what happens when a collider hits another collider. We chose the one called Bouncy, and lo and behold, when the Ball game object's Sphere Collider hits the Cube Collider of the Paddle, it reacts like a bouncy ball should. At our current phase of human technological progress, this is as close to a Make Game button as you're going to get!

Have a go hero

Unity's Standard Assets package provided us with a Bouncy physic material to use, but we could just as easily have created our own. If you want to create your own physic material from scratch, right-click/alternate-click on a blank area of the Project panel, and choose Create | Physic Material. Alternatively, you can click-and-hold the mouse button on the Create button at the top of the Project panel and choose Physic Material:

Have a go hero

A new Physic Material called (appropriately enough) New Physic Material appears in the Project panel. You can rename it the same way you renamed the Ball and Paddle game objects. Call it BouncyBall.

Click to select the Physic Material in the Project panel. Its parameters are listed in the Inspector. If you're desperate to know what everything does, click on the blue book icon with the question mark on it, and prepare to be bored to tears by talk of anisotropic friction. Yawn! What you really want to do is change the Bounciness to 1, and set the Bounce Combine to Maximum. Or choose your own settings if you just want to see what they do:

Have a go hero

Select the Ball again. Find where the Sphere Collider component's Material parameter is set to that built-in Bouncy Physic Material. Drag-and-drop your BouncyBall physic material into the slot where the built-in Bouncy one is. Alternatively, you can choose your BouncyBall physic material from the menu. The Bouncy physic material is swapped out for your own custom-created BouncyBall physic material.

Note

What a drag!

We'll be pulling that same drag-and-drop maneuver again and again as we use Unity. If you weren't feeling up to trying those last steps, don't worry; you'll get plenty of chances to drag stuff around the interface as we build more games.

Test the game by clicking the Play button. The paddle is flat, the ball is bouncy, and everything seems right with the world! We haven't programmed any interactivity yet, but try moving and rotating the paddle around while the game is running using the Unity tools to get a sense of how the ball might react when we rig up mouse control in the next chapter. (You'll have to deselect Maximize on Play to gain access to your tools to try this out in the Scene view.) While any changes you make to GameObjects in the Hierarchy don't "stick" while the game is playing, changes you make to elements in the Project panel do get saved. This feature allows you to adjust things such as the BouncyBall material's bounciness live while you play.