Game Development Reference
In Unity, a physics material is created in the Project and then added to the
object's Collider component. A physics material sets values for bounce
and friction. The bounciness of an object can be set between 0 (no
bounce) and 1 (full bounce) to simulate how much of a collision's force
comes back to the object. For example, for a tennis ball, set bounce to 1.
The friction value determines how well an object holds onto another
surface when rubbed together. For example, rubber on concrete has a
high friction value, whereas stone on ice has a low friction value. Friction
is a force that slows down movement. Friction can be set to 0 (no friction)
to an infinite number (total friction).
Unity Hands On
Step 1. Create a new Unity project with a sloping plane and cube as
shown in Figure 2.32 . Attach a Rigidbody to the cube. Press play and
watch the cube drop down until it hits the plane and then rolls the
rest of the way. Try to rotate the cube such that one side is parallel to
the plane as shown.
Step 2. To create physics material, in Project select the Create menu
and choose Physics Material, as shown in Figure 2.33 . Rename the
Step 3. Select the cube in the Hierarchy and locate its Box Collider
in the Inspector. The first property will be Material. Click on the
small circle to the very right of it and select the box physics
material from the pop-up window. If you play the application
at this point, there will be very little effect. Select box from
the Project. The view of this physics material will appear in the
Inspector as shown in Figure 2.34 . Set the Bounciness value to 1.
Press play to see the effect.
Step 4. To get a higher bounce, set the Bounce Combine value
to Maximum . These combine values tell the physics engine how
to work out the effect when two objects collide. When set to
maximum it will apply the maximum bounce factor out of the two
objects. If you set it to minimum the cube will not bounce, as the
plane has no bounciness value.
Step 5. Now try setting all the box physics material values to 0 and
the Friction Combine to minimum. Press play. With no bounce or
friction, the box will fall to the plane and then slide down as if the
surface was made of ice.