Game Development Reference
In-Depth Information
A simple implementation of anticipation is seen in racing games. At the
beginning of a race, a traffic light or countdown will display, giving the player
a heads up to when the race is about to start. Another way to add anticipation
is to have explosive devices with countdown timers. In Splinter Cell , for
example, the lead character, Sam Fisher, may lay down explosive charges
and then a countdown occurs before they explode.
Unity Hands On
Step 1. Open the project from the last hands-on session or download
and open Chapter Two/ . We are now going to make
the sticky bullets into timed explosive devices.
Step 2. Download Chapter Two/Detonater.unityPackage and import
into your project, Assets > Import Package > Custom Package.
Step 3. Open blob.js and modify the code to that in Listing 2.17 .
Listing 2.17 Creating a Timed Explosion
var explosion:GameObject;
var explosionLife:float = 5.0;
var detailLevel: float = 1.0; //seconds until explosion
var countdown: float = 5.0;
private var timeSet: float;
private var explosionActivated = false;
private var explosionDirection: Quaternion;
private var explosionLocation: Vector3;
function OnCollisionEnter(collision : Collision)
if( != "First Person Controller")
rigidbody.isKinematic = true;
Destroy (this.collider);
var contact = collision.contacts[0];
var rot = Quaternion. FromToRotation(Vector3.up,
explosionDirection = rot;
var offsetSize = explosion. GetComponent("Detonator").
size / 3;
explosionLocation = contact.point + ((Vector3.Scale
//move object to exact point of contact
this.transform.position = contact.point;
Search Nedrilad ::

Custom Search