Example #1
0
 void Start()
 {
     DrawLimb();
     if (child != null)
     {
         child.GetComponent <Limb>().MoveByOffset(jointOffset);
     }
 }
Example #2
0
    protected void BodypartToggleTrigger(bool isTrigger)
    {
        feet.GetComponent <Collider2D>().isTrigger = isTrigger;

        /*foreach (var b in limbs)
         * {
         *      b.GetComponent<Collider2D>().isTrigger = isTrigger;
         * }*/
    }
Example #3
0
    public void DetachLimb()
    {
        if (currentLimb != null)
        {
            currentLimb.GetComponent <Rigidbody>().useGravity  = true;
            currentLimb.GetComponent <Rigidbody>().isKinematic = false;
            currentLimb.transform.parent = null;
            currentLimb.SetAttachPoint(null);
            currentLimb           = null;
            localCollider.enabled = true;

            // tell the parent what has happened
            if (currentAnimalRef)
            {
                currentAnimalRef.OnChangeLimbs();
            }
        }
    }
Example #4
0
 DistanceJoint2D FindJointConnectedToSender(Limb sender)
 {
     foreach (DistanceJoint2D j in distJoints)
     {
         if (j.connectedBody == sender.GetComponent <Rigidbody2D>())
         {
             return(j);
         }
     }
     return(null);
 }
Example #5
0
    public void AttachLimb(Limb limb, bool playerAttach = false)
    {
        limb.transform.rotation  = transform.rotation;
        limb.transform.position  = transform.position;
        limb.transform.position -= limb.transform.TransformDirection(limb.anchorPointOffset);
        limb.GetComponent <Rigidbody>().useGravity  = false;
        limb.GetComponent <Rigidbody>().isKinematic = true;
        limb.transform.parent = transform;

        //Special for weird heads
        if (limbType_ != LimbType.Head && limb.limbType_ == LimbType.Head)
        {
            limb.transform.localPosition = Vector3.zero;
            if (limbType_ != LimbType.HindLeg)
            {
                limb.transform.localEulerAngles = new Vector3(0f, 180f, 0f);
            }
        }

        limb.SetAttachPoint(this);
        currentLimb           = limb;
        localCollider.enabled = false;

        if (playerAttach)
        {
            currentAnimationRoutine = StartCoroutine(AnimateLimb(attachAnimation));
        }
        if (currentIdleRoutine == null)
        {
            currentIdleRoutine = StartCoroutine(IdleAnimation());
        }
        // tell the parent what has happened
        if (currentAnimalRef)
        {
            currentAnimalRef.OnChangeLimbs();
        }
    }
Example #6
0
 void SwitchDirection(bool dangleFromSender, Limb sender)
 {
     foreach (DistanceJoint2D j in distJoints)
     {
         if (j.connectedBody == sender.GetComponent <Rigidbody2D>())
         {
             j.enabled = dangleFromSender;
         }
         else
         {
             j.enabled = !dangleFromSender;
             parent    = j.connectedBody.GetComponent <Limb>();
         }
     }
 }
Example #7
0
    public void SetRagdoll(bool e)
    {
        Limb latestLimb = null;

        //float latestTime = 0f;
        for (int i = 0; i < ragdollRigidbodies.Length; i++)
        {
            ragdollRigidbodies[i].isKinematic = !e;

            /*
             * if(bm != null && e) {
             *  velo = (bm.controller != null) ? bm.controller.velocity : (bm.velocity / Time.deltaTime);
             *  ragdollRigidbodies[i].AddForce(velo * ragdollForceFactor, ForceMode.Impulse);
             *
             *  Limb thisLimb = ragdollRigidbodies[i].GetComponent<Limb>();
             *  if(thisLimb != null) {
             *      if(thisLimb.lastForceTime > latestTime) {
             *          latestLimb = thisLimb;
             *          latestTime = thisLimb.lastForceTime;
             *      }
             *  }
             * }*/
        }

        if (latestLimb != null)
        {
            Rigidbody rigid = latestLimb.GetComponent <Rigidbody>();
            rigid.AddForce(latestLimb.ragdollVelocity, ForceMode.Impulse);

            Limb.ExplosionVelocity lbExpl = latestLimb.explosionVelocity;
            if (lbExpl != null)
            {
                rigid.AddExplosionForce(lbExpl.forceAmount, lbExpl.origin, lbExpl.forceRadius, lbExpl.upwardForce, ForceMode.Impulse);
            }
        }

        for (int i = 0; i < ragdollColliders.Length; i++)
        {
            ragdollColliders[i].isTrigger = !e;
        }
    }
Example #8
0
    public override void OnInspectorGUI()
    {
        Limb lb = target as Limb;

        if (lb.rootStats != null)
        {
            lb.limbType = (Limb.LimbType)EditorGUILayout.EnumPopup("Limb Type:", lb.limbType);
        }
        lb.rootStats = (BaseStats)EditorGUILayout.ObjectField("Root Stats:", lb.rootStats, typeof(BaseStats), true);

        if (lb.rootStats == null)
        {
            GUILayout.Box("Please assign a BaseStats component to 'Root Stats' in order to continue");
        }

        if (lb.rootStats != null)
        {
            DarkRef.GUISeparator(5f);

            lb.overrideMultiplier = EditorGUILayout.Toggle("Override:", lb.overrideMultiplier);

            EditorGUI.indentLevel += 1;
            if (lb.overrideMultiplier)
            {
                EditorGUIUtility.labelWidth = 200f;
                lb.damageMultOverride       = EditorGUILayout.FloatField("Damage Multiplier:", Mathf.Clamp(lb.damageMultOverride, 0f, 10f));
                EditorGUIUtility.LookLikeControls();
            }
            else
            {
                float readDisplayThing = 0f;
                if (lb.limbType == Limb.LimbType.Head)
                {
                    lb.damageMultOverride = 4f;
                    readDisplayThing      = 4f;
                }
                else if (lb.limbType == Limb.LimbType.Chest)
                {
                    lb.damageMultOverride = 1f;
                    readDisplayThing      = 1f;
                }
                else
                {
                    lb.damageMultOverride = 0.7f;
                    readDisplayThing      = 0.7f;
                }

                EditorGUIUtility.labelWidth = 200f;
                GUI.color        = Color.gray;
                readDisplayThing = EditorGUILayout.FloatField("Damage Multiplier:", readDisplayThing);
                GUI.color        = Color.white;
                EditorGUIUtility.LookLikeControls();
            }
            EditorGUI.indentLevel -= 1;
        }
        GUI.color = Color.red;
        if (lb.GetComponent <BaseStats>())
        {
            GUILayout.Box("NOTE: This component is assigned to an object that already have BaseStats. Are you sure this is correct?");
        }

        if (!lb.GetComponent <Collider>())
        {
            GUILayout.Box("WARNING: This component is assigned to an object without a collider! You must have a collider in order for this to work!");
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(lb);
        }
    }
Example #9
0
    void Update()
    {
        if (!cameraComp)
        {
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            selectedRigidbody = GetRigidbody();
            if (selectedRigidbody)
            {
                selectedLimb  = selectedRigidbody.GetComponent <Limb>();
                selectedJoint = selectedRigidbody.GetComponent <CharacterJoint>();
                if (selectedLimb && selectedJoint)
                {
                    Debug.Log("Setting break force.");
                    selectedLimb.SetColor(Color.red);
                    selectedJoint.breakForce = selectedLimb.breakForce;
                }
            }
        }
        if (selectedRigidbody && selectedLimb && !selectedJoint)
        {
            selectedRigidbody.constraints   = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ;
            selectedLimb.transform.rotation = selectedLimb.savedOrientation;
            if (Vector3.Distance(selectedLimb.transform.position, selectedLimb.jointParent.transform.position) < selectedLimb.attachThreshold)
            {
                selectedLimb.SetColor(Color.green);
            }
            else
            {
                selectedLimb.SetColor(Color.yellow);
            }
        }
        if (Input.GetMouseButtonUp(0) && selectedRigidbody)
        {
            if (selectedLimb)
            {
                selectedLimb.SetColor(Color.white);
                if (!selectedJoint && (Vector3.Distance(selectedLimb.transform.position, selectedLimb.jointParent.transform.position) < selectedLimb.attachThreshold))
                {
                    selectedRigidbody.constraints = RigidbodyConstraints.None | RigidbodyConstraints.FreezePositionZ;
                    selectedLimb.gameObject.AddComponent(typeof(CharacterJoint));
                    selectedLimb.joint = selectedLimb.GetComponent <CharacterJoint>();
                    selectedLimb.joint.autoConfigureConnectedAnchor = false;
                    selectedLimb.joint.connectedBody   = selectedLimb.jointParent;
                    selectedLimb.joint.connectedAnchor = selectedLimb.savedConnectedAnchor;
                    selectedLimb.joint.anchor          = selectedLimb.savedAnchor;
                    selectedJoint = selectedLimb.GetComponent <CharacterJoint>();
                }
            }
            if (selectedJoint)
            {
                selectedJoint.breakForce = Mathf.Infinity;
                selectedJoint            = null;
            }
            selectedRigidbody = null;
            selectedLimb      = null;
        }
    }