Esempio n. 1
0
        public static ConfigurableJoint GrabRigidbody(Rigidbody rb, Rigidbody grabPoint, Vector3 anchorOffset, bool freeRotation)
        {
            int id = rb.GetInstanceID();

            if (RigidbodyGrabbed(rb))
            {
                DetachRigidbody(rb, grabbedRBs[id], false);
            }

            // if we grabbed a ragdoll, make sure the controller (if any), goes ragdoll
            // with a full decay over all the bones
            RagdollBone grabbedBone = rb.GetComponent <RagdollBone>();

            if (grabbedBone)
            {
                if (grabbedBone.ragdoll.hasController)
                {
                    grabbedBone.ragdoll.controller.AddBoneDecay(1);
                    grabbedBone.ragdoll.controller.GoRagdoll("From grab");
                }
            }

            ConfigurableJoint j = MakeJointDefault(rb.gameObject.AddComponent <ConfigurableJoint>(), freeRotation, Vector3.zero, anchorOffset, grabPoint);

            grabbedRBs.Add(id, j);

            return(j);
        }
        public RagdollTransform(Transform transform, bool isBoneParent, bool isBone, bool isRoot)
        {
            this.transform = transform;

            originalRotation = transform.localRotation;
            originalPosition = transform.localPosition;

            this.isBoneParent = isBoneParent;
            this.isRoot       = isRoot;
            this.isBone       = isBone;

            bone      = transform.GetComponent <RagdollBone>();
            rigidbody = transform.GetComponent <Rigidbody>();
            if (rigidbody != null)
            {
                collisionDetectionModeBeforeKinematic = rigidbody.collisionDetectionMode;
            }
            collider = transform.GetComponent <Collider>();
            if (!isRoot)
            {
                joint = transform.GetComponent <ConfigurableJoint>();
                if (joint != null)
                {
                    connectedBody = joint.connectedBody;
                }
            }
        }
 void BroadcastCollisionStay(RagdollBone bone, Collision collision)
 {
     if (onCollisionStay != null)
     {
         onCollisionStay(bone, collision);
     }
 }
 void BroadcastCollisionExit(RagdollBone bone, Collision collision)
 {
     if (onCollisionExit != null)
     {
         onCollisionExit(bone, collision);
     }
 }
 /*
  *      send the message out that bone was collided
  *      (given to ragdollbone component)
  */
 void BroadcastCollisionEnter(RagdollBone bone, Collision collision)
 {
     if (onCollisionEnter != null)
     {
         onCollisionEnter(bone, collision);
     }
 }
Esempio n. 6
0
 public PhysicsHitElement(RaycastHit hit)
 {
     this.hitPoint    = hit.point;
     this.collider    = hit.collider;
     this.hitDistance = hit.distance;
     this.rigidbody   = collider.attachedRigidbody;
     ragdollBone      = collider.GetComponent <RagdollBone>();
 }
Esempio n. 7
0
        void BroadcastCollisionExit(RagdollBone bone, Collision collision)
        {
            if (onCollisionExit != null)
            {
                onCollisionExit(bone, collision);
            }

            //logicaPer.ragdollSuelo = false;
        }
Esempio n. 8
0
        /*
         *      send the message out that bone was collided
         *      (given to ragdollbone component)
         */
        void BroadcastCollisionEnter(RagdollBone bone, Collision collision)
        {
            if (onCollisionEnter != null)
            {
                onCollisionEnter(bone, collision);
            }

            //logicaPer.ragdollSuelo = true;
        }
 /*
  * when blending to animation, ignore collisons wiht static colliders that bones
  * come in contact with (this eliminates jitters from bone teleport trying to go through
  * the static collider).
  *
  * bone rigidbodies cannot be kinematic though, or else collisions wont exert forces in time
  * (when ragdollign on collision)
  */
 void CheckForBlendIgnoreStaticCollision(RagdollBone bone, Collision collision)
 {
     // if wee're blending or animated (teleporting bones)
     if (teleportingBones)
     {
         //if it's static
         if (collision.collider.attachedRigidbody == null)
         {
             blendBonesIgnoreStaticColliders.Add(new ColliderIgnorePair(bone.boneCollider, collision.collider));
         }
     }
 }
Esempio n. 10
0
            public Element(Transform transform, bool isPhysicsParent, bool isPhysicsBone, bool isRoot)
            {
                this.transform       = transform;
                this.isPhysicsParent = isPhysicsParent;
                this.isRoot          = isRoot;
                this.isPhysicsBone   = isPhysicsBone;

                bone      = transform.GetComponent <RagdollBone>();
                rigidbody = transform.GetComponent <Rigidbody>();
                collider  = transform.GetComponent <Collider>();
                if (!isRoot)
                {
                    joint = transform.GetComponent <ConfigurableJoint>();
                }
            }
        void HandleBoneDecayOnCollision(float collisionMagnitude2, RagdollBone bone, bool isCrushed, Collision collision)
        {
            if (isCrushed)
            {
                //Debug.LogWarning(bone + " / " + collision.transform.name + " CrUSHED");
                ragdollController.AddBoneDecay(bone.bone, 1, ragdollController.profile.neighborDecayMultiplier);
            }

            // if the magnitude is above the minimum threshold for adding decay
            else if (collisionMagnitude2 >= ragdollController.profile.decayMagnitudeRange.x * ragdollController.profile.decayMagnitudeRange.x)
            {
                float magnitude = Mathf.Sqrt(collisionMagnitude2);

                //linearly interpolate decay between 0 and 1 base on collision magnitude

                float linearDecay = (magnitude - ragdollController.profile.decayMagnitudeRange.x) / (ragdollController.profile.decayMagnitudeRange.y - ragdollController.profile.decayMagnitudeRange.x);

                //Debug.Log(bone + " / " + collision.transform.name + " mag: " + magnitude + " decay " + linearDecay);
                ragdollController.AddBoneDecay(bone.bone, linearDecay, ragdollController.profile.neighborDecayMultiplier);
            }
        }
Esempio n. 12
0
 /*
  *      callback called when ragdoll bone gets a collision
  */
 void OnRagdollCollisionEnter(RagdollBone bone, Collision collision)
 {
     CheckForBlendIgnoreStaticCollision(bone, collision);
 }
        /*
         *              callback called when ragdoll bone gets a collision
         *  then apply bone decay to those bones
         */
        void OnRagdollCollisionEnter(RagdollBone bone, Collision collision)
        {
            if (!enabled)
            {
                return;
            }

            //maybe add warp to master state for ragdoll check

            bool checkForRagdoll = ragdollController.state == RagdollControllerState.Animated || ragdollController.state == RagdollControllerState.BlendToAnimated;

            bool isFalling = ragdollController.state == RagdollControllerState.Falling;

            if (!isFalling && !checkForRagdoll)
            {
                return;
            }

            //check for and ignore self ragdoll collsion (only happens when falling)
            if (ragdollController.ragdoll.ColliderIsPartOfRagdoll(collision.collider))
            {
                return;
            }

            if (checkForRagdoll)
            {
                //if we're getting up, knock us out regardless of where the collision takes place
                if (!ragdollController.isGettingUp)
                {
                    // if it's below our step offset (plus a buffer)
                    // ignore it... we can just step on top of it
                    if (!CollisionIsAboveStepOffset(collision, ragdollController.charStepOffset, .1f))
                    {
                        return;
                    }
                }
            }


            bool  isCrushed           = CollisionHasCrushMass(collision) && CollisionIsAboveCrushOffset(collision, ragdollController.charHeight);
            float collisionMagnitude2 = collision.relativeVelocity.sqrMagnitude;

            if (checkForRagdoll)
            {
                // string message = "crush";
                // check if we're being crushed
                bool goRagdoll = isCrushed;

                // else check if the collision is above our incoming threhsold, (something being thrown at us)
                if (!goRagdoll)
                {
                    // message = "incoming";
                    goRagdoll = collisionMagnitude2 >= ragdollController.profile.incomingMagnitudeThreshold * ragdollController.profile.incomingMagnitudeThreshold;
                }

                // else check if we're travelling fast enough to go ragdoll (we ran into a wall or something...)
                if (!goRagdoll)
                {
                    // message = "outgoing";
                    collisionMagnitude2 = controllerVelocity.sqrMagnitude;
                    goRagdoll           = collisionMagnitude2 >= ragdollController.profile.outgoingMagnitudeThreshold * ragdollController.profile.outgoingMagnitudeThreshold;
                }

                if (!goRagdoll)
                {
                    return;
                }

                // Debug.Log( message + "/" + bone.name + " went ragdoll cuae of " + collision.collider.name + "/" + Mathf.Sqrt(collisionMagnitude2));
                ragdollController.GoRagdoll("from collision");
            }

            HandleBoneDecayOnCollision(collisionMagnitude2, bone, isCrushed, collision);
        }