How To Make Game Objects Bounce In Unity?
Learn how to make your Game Objects bounce on hitting a wall or the floor in Unity for Games, Applications, and AR/VR Experiences.
What are you going to learn?
In this article, I will show you how you can make your Game Objects bounce. This is useful when you need to make a ball bounce off the floor, the walls, or the ceiling. Let’s see how we can achieve this in Unity.
The key step here is to use a Physics material and change the properties of it so that it behaves like a bouncy object. It is easier than you think.
Here are the steps —
Step 1: Add a plane and a sphere to an empty scene.
The plane represents the floor and the sphere will be the ball that bounces on that floor.
I also added a blue color to the floor. If you don’t know how to do that, you can check out my article - “How To Apply Color To A Game Object In Unity?”
Step 2: Add the Rigidbody component to the Ball
Since we need our ball to obey the laws of physics, we will have to attach the Rigidbody component to it. Make sure the Use Gravity box is checked. We don’t want the ball to float in space.
Step 3: Create a “Bouncy” material
Step 4: Change the properties of the Bouncy material
Select the Bouncy Material > You should be able to view the properties of this material on the right-hand side i.e the Inspector panel. Now change the properties.
Step 5: Apply the material to the sphere
Now apply this material to the sphere(i.e the ball) in our scene.
That’s it. This step confirms that the sphere will bounce on our floor.
Step 6: Hit the play button
Bonus: You can also control the number of times the ball bounces. Try experimenting with different properties of the “Bouncy” material.
Hopefully, you didn’t face any problems in any of the steps above. In case you did, comment below and I will help you out.😉