Game Development Reference
In-Depth Information
and the cube are calculated by the physics engine according to each game object's physical
properties. The cube responds to the impact of the falling sphere by sliding in one direction while the
sphere rolls away in the other. Notice that the sphere doesn't bounce at all.
Unity does provide a few basic physic materials in its Standard Assets package. In the top menu of
the editor, select Assets ➤ Import Package ➤ Physic Materials. Go ahead and import all of them so
you have them in your project to experiment with.
Note At the time of this writing, Unity's Standard Assets and Sample Assets (beta) are being combined.
If the Physic Materials here don't import properly, download and import the Sample Assets (beta) package
from the Asset Store then use the search bar in the Project panel to find the Bouncy physic material.
Drag Bouncy from the Standard Assets ➤ Physic Materials folder in the Project panel to the Sphere's
Material property of the Sphere Collider component in the Inspector. Save the scene. Now when you
playtest, the Sphere game object has some distinct bounciness to it when it collides with the Cube
and then the Plane.
The physic materials in the Standard Assets package are meant to be starting points. For your game
and your game objects to be distinctive, you should further customize and refine their physical
characteristics.
LookAt
Take a step away from the topic of Physics for a moment. Now that you have objects moving
around, you may find you'd like your camera to keep pointing at an object as it moves. LookAt is the
handy function that does just that. Still using your PhysicMaterialsTest scene, in the Project panel
create a new script with Create ➤ Javascript, and name it PointCamera. Double-click to open in
MonoDevelop and edit the contents as follows:
#pragma strict
var cameraTarget : Transform;
function Update () {
transform.LookAt(cameraTarget);
}
Save the script and attach it to the Main Camera. Breaking this down:
(1) var cameraTarget : Transform;
If you don't specify public or private scope the Transform type variable cameraTarget you declare
here will by default be a public variable available to you through the Inspector.
(2) transform.LookAt(cameraTarget);
 
Search WWH ::




Custom Search