Game Development Reference
In-Depth Information
Tests to make sure the
childRigidBodies
contains any elements. No elements would equal a “null” state.
(6) for (var childRigidBody : Rigidbody in childRigidBodies)
{
childRigidBody.isKinematic = false;
}
This is a
for
loop in action, where for each element in the array
childRigidBodies
, a reference
variable
childRigidBody
of type
Rigidbody
is created, then its
isKinematic
property is set to
false
.
Setting
isKinematic
to false means the rigidbody is now recognized by the physics engine.
(7) if (childColliders != null)
Tests to make sure the childColliders contains any elements.
(8) for (var childCollider : Collider in childColliders)
{
childCollider.enabled = true;
}
Another
for
loop, where for each element in the array
childColliders
, a reference variable
childCollider
of type
Collider
is created then enabled.
(9) gameObject.collider.enabled = false;
(10) gameObject.rigidbody.isKinematic = true;
(11) gameObject.GetComponent(Animator).enabled = false;
(12) gameObject.GetComponent(ThirdPersonCharacter).enabled = false;
(13) gameObject.GetComponent(ThirdPersonUserControl).enabled = false;
(7) and (8) activate the ragdoll child objects to be accessible by the physics engine, but the Animator and
scripts that were running the player character animations and movements also need to be deactivated.
(9) and (10) are simple dot notation property-changing statements where the parent Capsule Collider
component of the Third Person Character Ragdoll is disabled and the parent Rigidbody component
is set to
isKinematic
—meaning not recognized by the physics engine.
(11), (12), and (13) are slightly different syntax, because the
Collider
and
Rigidbody
classes inherit
directly from the
gameObject
class. Animators and Scripts belong to the
MonoBehavior
class, so must
be obtained by name using the
GetComponent
function to access their properties and disable them.
Save the GoRagdoll script and attach it to Third Person Character Ragdoll.
Note
If the Sample Assets (beta) assets are integrated into your Standard Assets folder already, you can
skip the following step.
If you are working with the Sample Assets (beta) package, you will get an “Unknown identifier:
Third Person Character” error. The compiler compiles JavaScript files first so it does not recognize
the references to “Third Person Character” or the “Third Person User Control” C# scripts not yet
compiled being called from our GoRagdoll script in the
GotoRagdoll()
function.