Пример #1
0
        private void ConvertToRagdoll(GameObject resultNeg, GameObject resultPos, LazyActionRunner lazyRunnerNeg, LazyActionRunner lazyRunnerPos)
        {
            Animator animator                = this.GetComponent <Animator>();
            Vector3  velocityContinue        = animator.velocity;
            Vector3  angularVelocityContinue = animator.angularVelocity;

            ConvertToRagdoll(resultNeg, velocityContinue, angularVelocityContinue, lazyRunnerNeg);
            ConvertToRagdoll(resultPos, velocityContinue, angularVelocityContinue, lazyRunnerPos);
        }
Пример #2
0
        private void ConvertToRagdoll(GameObject go, Vector3 velocityContinue, Vector3 angularVelocityContinue, LazyActionRunner lazyRunner)
        {
            Profiler.BeginSample("ConvertToRagdoll");
            // if your player is dead, you do not need animator or collision collider
            Animator animator        = go.GetComponent <Animator>();
            Collider triggerCollider = go.GetComponent <Collider>();

            UnityEngine.Object.Destroy(animator);
            UnityEngine.Object.Destroy(triggerCollider);

            StartCoroutine(SmoothDepenetration(go, velocityContinue, angularVelocityContinue));

            var collidersArr = go.GetComponentsInChildren <Collider>();

            for (int i = 0; i < collidersArr.Length; i++)
            {
                var collider = collidersArr[i];
                if (collider == triggerCollider)
                {
                    continue;
                }

                collider.isTrigger = false;
            }

            // set rigid bodies as non kinematic
            var rigidsArr = go.GetComponentsInChildren <Rigidbody>();

            for (int i = 0; i < rigidsArr.Length; i++)
            {
                var rigid = rigidsArr[i];
                rigid.isKinematic = false;
            }
            Profiler.EndSample();
        }