Game Development Reference
In-Depth Information
Step 19. Finally, to make the bullet object squash when it hits the
wall, modify your script to that in Listing 2.16 .
Listing 2.16 Causing a Squash Effect by Changing an
Object's Scale
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,
this.transform.position = contact.point;
this.transform.rotation = rot;
this.transform.localScale.y*= 0.2;
function Update () {
Step 20. Save and play. The code now destroys the collider
component to stop the FPC from hitting the stationary bullets. If
you take this line out you will notice that the bullets create barriers
the FPC collides with. Data are taken from the collision and used to
rotate the object just as the y axis is aligned with the normal of the
point of contact. This means that when the y axis is scaled down,
the object presses flat to the object it collided with. The x and z
scales can then be resized based on the collision velocity to create
a bigger splat .
Step 21. Create a shiny black material for the bullet prefab, and take
a walk around the warehouse, leaving blobs everywhere. Note that
funny unaligned blobs will be caused by collisions with other complex
meshes, such as chairs. This code works best with walls, floors, and
other large flat areas.
Search Nedrilad ::

Custom Search