// Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Q))
     {
         theRdollHandlerScript.EnableRagdoll(toggleRagdoll, theRdollHandlerScript.rigidbodies);
         toggleRagdoll = !toggleRagdoll;
     }
 }
Exemplo n.º 2
0
 void AddForce()
 {
     //This function turns the ragdoll on (using the HandleRagdoll script)
     ragdollHandler.EnableRagdoll(true);
     //And it applies the force in the camera direction, with the forceMagniture strenght
     force = (hitInfo.point - Camera.main.transform.position).normalized * forceMagnitude;
     hitBodyPart.AddForce(force, ForceMode.Impulse);
 }
Exemplo n.º 3
0
    void OnTriggerEnter(Collider col)
    {
        if (col.tag == "bullet")
        {
            Debug.Log(col.name);
            ///col.tag = "Untagged"; Make bullet untagged in the zombie health script
            Debug.Log("Zombie hit by a bullet.");

            theZombieHealthScript.currentHealth -= col.gameObject.GetComponent <bulletBehaviour>().bulletDamage;

            // so that if another zombie touches already stuck arrow in another zombie. He should ignore it
            Rigidbody hitPodyPart = selectedRigidbodyToApplyForceWhenBullerHits[selectBodyPartToapplyForce];  // force would be applied on selected body part only
            //GameObject tempArrow = col.gameObject;
            col.attachedRigidbody.isKinematic = true;
            col.transform.position            = hitPodyPart.gameObject.transform.position;

            Vector3 arrowDir = col.transform.up;
            col.transform.position = col.transform.position + penetrationDepth * arrowDir;
            col.transform.parent   = hitPodyPart.transform;


            if (theZombieHealthScript.currentHealth <= 0)   // If die then only ragdoll and if tag is arrow then only apply Force to that ragdoll
            {
                force = -1 * transform.forward * forceMagnitude;


                //int randomSelect = Random.Range(1, 4);
                //selectBodyPartToapplyForce = randomSelect;

                //GameObject tempArrow = col.gameObject;
                col.attachedRigidbody.isKinematic = true;
                col.transform.position            = hitPodyPart.gameObject.transform.position;

                col.transform.position = col.transform.position + penetrationDepth * arrowDir;
                col.transform.parent   = hitPodyPart.transform;

                Debug.Log(selectedRigidbodyToApplyForceWhenBullerHits[selectBodyPartToapplyForce].name);
                if (hitPodyPart != null)
                {
                    ragdollHandler.EnableRagdoll(true, ragdollHandler.rigidbodies);

                    //// trying by using col.transform.yp whihc is arrow front dir
                    /////hitPodyPart.AddForce(col.GetComponent<Rigidbody>().velocity.normalized * forceMagnitude, ForceMode.Impulse);
                    hitPodyPart.AddForce(-1 * arrowDir * forceMagnitude, ForceMode.Impulse);
                }

                this.gameObject.GetComponent <NavMeshAgent>().isStopped = true;
                //Destroy(col.gameObject);
            }
        }
    }
    void Decapitate()
    {
        //We only can decapitate the character once, so we set the wasSevered flag to true
        wasSevered = true;
        if (ragdollHandler != null)
        {
            //If we have a HandleRagdoll script attached, we should enable the ragdoll
            //and disable the script
            ragdollHandler.EnableRagdoll(true);
            ragdollHandler.enabled = false;
        }
        Joint headJoint = head.GetComponent <Joint>();

        if (headJoint != null)
        {
            //Because we will scale the head transform to 0, we should destroy the head joint
            Destroy(headJoint);
        }
        Collider headCollider = head.GetComponent <Collider>();

        if (headCollider != null)
        {
            //And the collider on the head
            Destroy(headCollider);
        }
        Rigidbody headRigidBody = head.GetComponent <Rigidbody>();

        if (headRigidBody != null)
        {
            //And the rigid body attached to it
            Destroy(headRigidBody);
        }
        //We spawn a headPrefab in the place of the headMarker (this is a Transform that stores original head position)
        GameObject spawnedHead   = (GameObject)GameObject.Instantiate(headPrefab, headMarker.position, headMarker.rotation);
        Rigidbody  spawnedHeadRB = spawnedHead.GetComponent <Rigidbody>();

        if (spawnedHeadRB != null)
        {
            //After we spawn the head, we add a force and torque to it to launch it in the air and rotate
            spawnedHeadRB.AddForce(RandomVector(randomForce1, randomForce2), ForceMode.Impulse);
            spawnedHeadRB.AddTorque(RandomVector(randomTorque1, randomTorque2), ForceMode.Impulse);
        }
        //Then we scale the head to 0, to hide it
        head.localScale = Vector3.zero;
        //We also spawn a neckPrefab to mask the scaled down head.
        GameObject spawnedNeck = (GameObject)GameObject.Instantiate(neckPrefab, neckMarker.position, neckMarker.rotation);

        spawnedNeck.transform.parent = neckMarker;
    }