Game Development Reference
In-Depth Information
Fig 2.37 Setting a script variable to
the value of a prefab object.
Step 17. We are now going to create sticky bullets. Open the blob.js
file. Enter the script from Listing 2.15 .
Listing 2.15 Turn off an Object's Physics on a Collision
function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.name !=
"First Person Controller")
{
rigidbody.isKinematic = true;
}
}
function Update () {
}
Step 18. Save and play. You will have created sticky bullets that stop
moving the instance they collide with something. The isKinematic
setting in the script will turn off physics effects on the object when it
is set to true. A test is performed to check if the object has hit the FPC
before it turns off the physics. This is used to ensure that the bullets
don't stick to the FPC.
Search Nedrilad ::




Custom Search