Game Development Reference
In-Depth Information
Figure 7-14. The player character collapsed according to ragdoll physics
If you look closely, you will notice that the head and heels of the player character appear to sink into
the surface he is lying on. You can fine-tune this for your game's player character model by adjusting
the size and position of the individual ragdoll colliders.
Kill Zone
You can also write a KillOnTrigger script to use for invisible kill zones. Since the obstacle course
is an elevated track, something dire should happen to the player if he falls off, such as an invisible
kill zone over the floor that kills the player character on impact. In the Assets ➤ Scripts folder in
the Project panel, select Create ➤ JavaScript, name the new script KillOnTrigger, and open it in
MonoDevelop. You can cut and paste the code from KillOnCollision, then change the function name
from OnCollisionEnter(other : Collision) to OnTriggerEnter(other : Collider) as follows, then
save the script:
#pragma strict
function OnTriggerEnter(other : Collider) {
if (other.gameObject.name == "Third Person Character Ragdoll")
{
other.gameObject.GetComponent(GoRagdoll).GotoRagdoll();
}
}
In the Hierarchy select Create ➤ Cube and name it KillZone_Floor. In the Inspector, give it a
Transform position of (0, 0, 120) and a scale of (30, 1, 200). Uncheck the Mesh Renderer component
to disable it, making the kill zone invisible. Check Is Trigger in the Box Collider component. Select
Add Component ➤ Scripts and choose KillOnTrigger. Save the scene, save the project, and playtest.
When your player falls off the elevated track, the ragdoll physics take effect just before he hits the floor.
 
Search WWH ::




Custom Search