Game Development Reference
In-Depth Information
The Dynamic Friction property is used when the object is already moving. A value of 0 means no
loss of energy—that is, it is the most slippery so the object will slide a good distance. A value of 1 is
the opposite end of the scale: the moving object will stop moving quickly.
Static Friction is when the object is at rest. This is the friction that must be overcome in order to get
the object moving. This property has the same scale of 0 to 1 where 0 is virtually frictionless and 1
takes a lot of force to get the object moving.
Bounciness also has a scale of 0 to 1, where 0 means all energy is lost—no bounce—while 1 means
no energy is lost and the object is super bouncy.
Friction Combine and Bounce Combine give you options for how to combine the frictions of the
two colliding game objects. You have the choice of Average for averaging the two values, Minimum
to use the smallest value, Maximum for the greatest value, and Multiply to multiply the two values.
Friction Direction 2 allows you to create a different friction for the game object in a different
direction across its surface. An example would be going with or against the grain of wood. If you
choose to have this second directional friction, you modify the behavior with Dynamic Friction 2
and Static Friction 2 just like you did with Dynamic Friction and Static Friction.
Time to give it a try. With the Ice physic material asset selected, change Dynamic Friction and
Static Friction both to 0. Now apply this physic material to the cube and the plane game objects
by dragging and dropping it from the Project panel onto the objects in the Scene view, or in the
Inspector by using the circle selection button to the right of the Material property field of the Collider
component and choosing it from the menu that appears.
The last thing you need for testing is the ability to apply a force to the cube. In the Project panel
select Create ➤ JavaScript and name the new script Push. Double-click it to open for editing in
MonoDevelop. Delete the Start() and Update() functions, then add the following code:
public var aForce : float = 50;
function OnMouseDown () {
rigidbody.AddForce (Vector3.forward * aForce);
}
You've used this code before. You can adjust the amount of force of the push in the Inspector
with the public variable aForce . In the OnMouseDown() function, you apply aForce to the rigidbody
component of the game object that the physics engine is tracking. Save the script and attach it to
the Cube game object. Save the scene. Play to test and when you click the cube, it begins sliding.
Since both it and the plane are essentially frictionless, it will continue to slide until it falls off. Test
changing the Dynamic and Static Friction values of the Icy physic material, then push the Cube
game object in Play mode. When you are finished experimenting, reset the Dynamic Friction and
Static Friction properties of the Icy physic material to 0.
Bounciness
To test out bounciness, add a Sphere game object to the Scene with a Transform position of (0.5, 2, 0).
Add a Rigidbody component to it just as you did for the Cube game object. Save the scene and Play.
The sphere falls and impacts the edge of the cube, then falls to the plane. The movement of the sphere
 
Search WWH ::




Custom Search