コード例 #1
0
    void CreateAndConnectMuscles(Transform ragdollBone, Transform animBone)
    {
        if (ragdollBone.tag == "RagdollBone")
        {
            Rigidbody boneRb = ragdollBone.GetComponent <Rigidbody>();
            if (!boneRb)
            {
                boneRb = ragdollBone.gameObject.AddComponent <Rigidbody>();
            }
            boneRb.mass        = boneMass;
            boneRb.drag        = 0.0f;
            boneRb.angularDrag = 0.0f;
            boneRb.useGravity  = useGravity;

            Muscle muscle = ragdollBone.gameObject.AddComponent <Muscle>();
            muscle.ragdollRoot     = transform;
            muscle.animatedRigRoot = animatedTargetRigHip;
            muscle.SetAnimationTarget(animBone);
            Muscle parentMuscle = ragdollBone.parent.GetComponent <Muscle>();
            if (parentMuscle)
            {
                muscle.SetParent(parentMuscle);

                JointDrive posMatchingSpring = new JointDrive();
                posMatchingSpring.positionSpring = 1000.0f;
                posMatchingSpring.positionDamper = 100.0f;
                posMatchingSpring.maximumForce   = Mathf.Infinity;
                muscle.positionMatchingSpring    = posMatchingSpring;
            }
            this.ragdollMuscles.Add(muscle);

            for (int i = 0; i < ragdollBone.childCount; i++)
            {
                Transform childRagdollBone = ragdollBone.GetChild(i);
                Transform childAnimBone    = animBone.GetChild(i);
                CreateAndConnectMuscles(childRagdollBone, childAnimBone);
            }
        }
    }