void Update()
        {
            if (characterMovement.freeFalling)
            {
                ragdollController.GoRagdoll("free fall");
            }

            // if we're falling, dont let us go "up"
            // ragdoll was falling up stairs...
            characterMovement.preventUpwardsGroundedMotion = ragdollController.state == RagdollControllerState.Falling;

            // dont accept any movement changes from player input, or ai input
            characterMovement.disableExternalMovement = ragdollController.state != RagdollControllerState.Animated || ragdollController.isGettingUp;

            /*
             *  skip moving the main transform if we're completely ragdolled, or waiting to reorient
             *  the main transform via the ragdoll controller
             */
            characterMovement.disableAllMovement = ragdollController.state == RagdollControllerState.Ragdolled || ragdollController.state == RagdollControllerState.TeleportMasterToRagdoll;


            /*
             *  when animated or blending to animation
             *      use character controller movement
             *
             *      it has less step offset jitter than the normal transform movement
             *      especially when getting up
             *
             *  else when falling:
             *
             *      use normal transform stuff (dont want the character controller collisions messing stuff up)
             *      for falling /calculating fall ( we need all exterion collisions to reach ragdol bones)
             *      and teh characer chontroller acts as a 'protective shell' when it's enabled
             */

            characterMovement.usePhysicsForMove = ragdollController.state == RagdollControllerState.Animated || ragdollController.state == RagdollControllerState.BlendToAnimated;


            //cehck if we started getting up
            if (ragdollController.state == RagdollControllerState.BlendToAnimated)
            {
                //set zero speed
                if (characterMovement.currentSpeed != 0)
                {
                    characterMovement.SetMovementSpeed(0);
                }
            }

            int currentSpeed = (int)characterMovement.currentSpeed;

            if (currentSpeed < 0 || currentSpeed >= fallDecaySpeeds.Length)
            {
                Debug.LogError("current speed: " + currentSpeed + " :: out of range for fall decays");
            }
            else
            {
                //set the ragdolls fall speed based on our speed
                ragdollController.SetFallSpeed(fallDecaySpeeds[(int)characterMovement.currentSpeed]);
            }
        }
Beispiel #2
0
        void FixedUpdate()
        {
            bool isFalling;

            CheckPhysics(out isFalling);

            if (isFalling)
            {
                ragdollController.GoRagdoll();
            }

            ApplyMovement(UpdateMode.FixedUpdate);
        }
Beispiel #3
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "dano" && !logicaPer.tirado)
        {
            ragdoll.gameObject.SetActive(true);
            animatedM.gameObject.SetActive(false);
            //nav.enabled = false;
            // myRagController.GoRagdoll("manual");
            myRagController.GoRagdoll("");
            logicaPer.tirado                    = true;
            logicaPer.armaDisparo               = false;
            logicaPer.rb.isKinematic            = true;
            logicaPer.rb.isKinematic            = false;
            miConexionComponentes.refrescoCaido = miConexionComponentes.tiempo + 4f;
            miCabeza.contadorDeColision         = 0;
            if (other.GetComponentInParent <movimientoProyectil>() != null)
            {
                /*PosicionD = other.GetComponentInParent<movimientoProyectil>().posicion;
                 * var variable = PosicionD -transform.position;
                 * miConexionComponentes.hips.GetComponent<Rigidbody>().AddForce(variable.normalized * bulletForce, ForceMode.VelocityChange);*/
                PosicionD = other.transform.position;
                var variable = transform.position - PosicionD;
                miConexionComponentes.hips.GetComponent <Rigidbody>().AddForce((variable.normalized * other.GetComponentInParent <movimientoProyectil>().bulletForce) + new Vector3(0, 10, 0), ForceMode.VelocityChange);
            }
            if (other.GetComponentInParent <movimientoProyectil2>() != null)
            {
                /*PosicionD = other.GetComponentInParent<movimientoProyectil2>().posicion;
                 * var variable = PosicionD - transform.position;
                 * miConexionComponentes.hips.GetComponent<Rigidbody>().AddForce(variable.normalized * bulletForce, ForceMode.VelocityChange);*/
                PosicionD = other.transform.position;
                var variable = transform.position - PosicionD;
                miConexionComponentes.hips.GetComponent <Rigidbody>().AddForce((variable.normalized * other.GetComponentInParent <movimientoProyectil2>().bulletForce) + new Vector3(0, 10, 0), ForceMode.VelocityChange);
            }
            if (other.GetComponentInParent <movimientoProyectil3>() != null)
            {
                PosicionD = other.transform.position;
                var variable = PosicionD - transform.position;
                miConexionComponentes.hips.GetComponent <Rigidbody>().AddForce(variable.normalized * other.GetComponentInParent <movimientoProyectil3>().bulletForce, ForceMode.VelocityChange);

                /*PosicionD = other.transform.position;
                 * var variable = transform.position - PosicionD;
                 * miConexionComponentes.hips.GetComponent<Rigidbody>().AddForce(variable.normalized * other.GetComponentInParent<movimientoProyectil3>().bulletForce, ForceMode.VelocityChange);*/
            }
            if (other.GetComponentInParent <Chaser>() != null)
            {
                PosicionD = other.transform.position;
                var variable = transform.position - PosicionD;
                miConexionComponentes.hips.GetComponent <Rigidbody>().AddForce((((variable.normalized * 3f)) + new Vector3(0, 5, 0)), ForceMode.VelocityChange);
            }
        }
    }
Beispiel #4
0
        void OnDeath(Damageable damageable, DamageMessage damageMessage)
        {
            // if (damageable != null) {

            //     RagdollTransform damagedBone = null;

            //     if ( ragdollController.ragdoll.Transform2HumanBone (damageable.transform, out damagedBone) ) {

            //         // set bone decay for the hit bone, so the physics will affect it
            //         // (slightly lower for neighbor bones)
            //         float mainDecay = 1;
            //         float neighborMultiplier = .75f;
            //         ragdollController.AddBoneDecay(damagedBone.bone.bone, mainDecay, neighborMultiplier);
            //     }
            // }

            //make it go ragdoll
            ragdollController.GoRagdoll("death");

            ragdollController.disableGetUp = true;
        }
Beispiel #5
0
        IEnumerator ShootBullet(Ray ray)
        {
            yield return(new WaitForFixedUpdate());

            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100f, shootMask, QueryTriggerInteraction.Ignore))
            {
                //check if we hit a ragdoll bone
                RagdollBone ragdollBone = hit.transform.GetComponent <RagdollBone>();

                if (ragdollBone)
                {
                    // check if the ragdoll has a controller
                    if (ragdollBone.ragdoll.hasController)
                    {
                        RagdollController controller = ragdollBone.ragdoll.controller;

                        // set bone decay for the hit bone, so the physics will affect it
                        // slightly lower for neighbor bones

                        float mainDecay          = 1;
                        float neighborMultiplier = .75f;
                        controller.SetBoneDecay(ragdollBone.bone, mainDecay, neighborMultiplier);

                        //make it go ragdoll
                        controller.GoRagdoll();
                    }
                }

                // shoot normally

                Rigidbody rb = hit.transform.GetComponent <Rigidbody>();

                if (rb)
                {
                    rb.AddForceAtPosition(ray.direction.normalized * modifiedBulletForce, hit.point, ForceMode.VelocityChange);
                }
            }
        }
Beispiel #6
0
        void Update()
        {
            if (CustomInputManager.InputManager.GetKeyDown(KeyCode.R))
            {
                ragdollController.GoRagdoll("manual");
            }

            if (CustomInputManager.InputManager.GetButtonDown("UI_Up"))
            {
                GameManager.timeDilation += .1f;
            }
            if (CustomInputManager.InputManager.GetButtonDown("UI_Down"))
            {
                GameManager.timeDilation -= .1f;
            }

            turner.GetComponent <Turner_Animated>().autoTurnAnimate = movement.speed == 0;

            combat.SetAiming(CustomInputManager.InputManager.GetButton("Aim"));
            combat.SetFiring(CustomInputManager.InputManager.GetButton("Fire"));

            CheckDirectionalMovement();
        }
        /*
         *              callback called when ragdoll bone gets a collision
         *  then apply bone decay to those bones
         */
        void OnRagdollCollisionEnter(RagdollBone bone, Collision collision)
        {
            float stepOffset = characterController.stepOffset;
            float charHeight = characterController.height;


            //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, stepOffset, .1f))
                    {
                        return;
                    }
                }
            }


            bool  isCrushed           = CollisionHasCrushMass(collision) && CollisionIsAboveCrushOffset(collision, 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 >= incomingMagnitudeThreshold * 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 >= outgoingMagnitudeThreshold * outgoingMagnitudeThreshold;
                }

                if (!goRagdoll)
                {
                    return;
                }

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


            HandleBoneDecayOnCollision(collisionMagnitude2, bone, isCrushed, collision);
        }
Beispiel #8
0
        void Update()
        {
            CheckCameraTarget();
            UpdateSloMo();

            /*
             *  shoot from the clicked position
             */
            if (Input.GetMouseButtonDown(0))
            {
                shooting.Shoot(cam.ScreenPointToRay(Input.mousePosition));
            }

            /*
             *  launch the ball from the camera
             */
            if (Input.GetKeyDown(KeyCode.B))
            {
                Ray ray = cam.ScreenPointToRay(Input.mousePosition);
                cannonBall.Launch(ray.origin, ray.origin + ray.direction * 50, ballScale, ballMass, ballVelocity);
            }

            if (controlledCharacter)
            {
                RagdollController ragdollController   = controlledCharacter.ragdollController;
                Vector3           ragRootBonePosition = ragdollController.ragdoll.RootBone().transform.position;

                /*
                 *  drop teh ball on the controlled character
                 */
                if (Input.GetKeyDown(KeyCode.U))
                {
                    cannonBall.Launch(ragRootBonePosition + Vector3.up * 25, ragRootBonePosition, ballScale, ballMass, 0);
                }

                /*
                 *  manually ragdoll the controlled character
                 */
                if (Input.GetKeyDown(KeyCode.R))
                {
                    ragdollController.GoRagdoll();
                }

                /*
                 *  moved the controlled character
                 */
                if (!controlledCharacter.overrideControl)
                {
                    //do turning
                    controlledCharacter.transform.Rotate(0f, Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime, 0f);
                    //set speed
                    controlledCharacter.SetMovementSpeed(Input.GetAxis("Vertical") * (Input.GetKey(KeyCode.LeftShift) ? 2 : 1));
                }

                //disable char control
                if (Input.GetKeyDown(KeyCode.P))
                {
                    AttachToCharacter(null);
                }
            }
            else
            {
                /*
                 *  look for character to control
                 */
                if (Input.GetMouseButtonDown(1))
                {
                    StartCoroutine(CheckForCharacter(cam.ScreenPointToRay(Input.mousePosition)));
                }
            }
        }
Beispiel #9
0
        void Update()
        {
            UpdateRagdollGrabberPosition();

            CheckCameraTarget();
            UpdateSloMo();

            /* shoot from the clicked position */
            if (Input.GetMouseButtonDown(0))
            {
                if (currentAmmoType != null)
                {
                    currentAmmoType.FireAmmo(this, cam.ScreenPointToRay(Input.mousePosition), shootMask, 1);
                }
            }
            if (Input.GetMouseButtonDown(1))
            {
                StartCoroutine(CheckForRagdollGrab(cam.ScreenPointToRay(Input.mousePosition)));
            }

            /* launch the ball from the camera */
            if (Input.GetKeyDown(KeyCode.B))
            {
                GameObject.FindObjectOfType <DemoSceneController>().SwitchActiveScene();
            }
            /* drop teh ball on the controlled character */
            if (Input.GetKeyDown(KeyCode.E))
            {
                ToggleAmmoType();
            }

            if (controlledCharacter)
            {
                /* manually ragdoll the controlled character */
                if (Input.GetKeyDown(KeyCode.R))
                {
                    ragdollController.GoRagdoll("manual");
                }

                /* moved the controlled character */
                if (!controlledCharacter.disableExternalMovement)
                {
                    //do turning
                    controlledCharacter.transform.Rotate(0f, Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime, 0f);
                    //set speed
                    controlledCharacter.SetMovementSpeed(Input.GetAxis("Vertical") * (Input.GetKey(KeyCode.LeftShift) ? 2 : 1));
                }

                //disable char control
                if (Input.GetKeyDown(KeyCode.P))
                {
                    AttachToCharacter(null);
                }
            }
            else
            {
                /* look for character to control */
                if (Input.GetKeyDown(KeyCode.P))
                {
                    StartCoroutine(CheckForCharacter(cam.ScreenPointToRay(Input.mousePosition)));
                }
            }
        }
    // Update is called once per frame
    void Update()
    {
        tiempo = tiempo + 1 * Time.deltaTime;
        if (Input.GetKeyDown(KeyCode.G))
        {
            //hips.transform.position = animatedM.transform.position;
            //hips.transform.position += new Vector3(0, .9f, 0);
            //transform.rotation = animatedM.transform.rotation;
        }



        /*  if (!dead)
         * {
         *    //myRag.gameObject.SetActive(true);
         *    //myRag.gameObject.SetActive(false);
         *
         *
         *    myRag.transform.position = animatedM.transform.position;
         *
         *    //hips.transform.position = animatedM.transform.position;
         *    //hips.transform.position += new Vector3(0,.9f,0);
         *    transform.position = animatedM.transform.position;
         *
         *    transform.rotation = animatedM.transform.rotation;
         *    //myRagController.GetUpImmediate();
         *
         * }*/
        /*
         *      if (dead)
         *      {
         *          //myRag.gameObject.SetActive(false);
         *          //myRag.gameObject.SetActive(true);
         *
         *          myRagController.GoRagdoll("manual");
         *
         *          //myRagController.GetUpImmediate();
         *          //myRagController.GoRagdoll("manual");
         *          animatedM.transform.rotation = transform.rotation;
         *          //animatedM.transform.position = myRag.transform.position;
         *          animatedM.transform.position = hips.transform.position;
         *
         *      }*/
        cam2.transform.position = hips.transform.position;

        /*if (logicaPer.tirado && !myRagController.isGettingUp)
         * {
         *  animatedM.transform.position = hips.transform.position;
         * }*/
        /* if (Input.GetMouseButton(0))
         * {
         *   float bulletForce = 4;
         *   RaycastHit hit;
         *   Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         *   if (Physics.Raycast(ray, out hit))
         *   {
         *
         *
         *       //add force to it's rigidbody
         *       hips.GetComponent<Rigidbody>().AddForceAtPosition(ray.direction.normalized * bulletForce / Time.timeScale, hit.point, ForceMode.VelocityChange);
         *   }
         *  // hips.GetComponent<Rigidbody>().AddForce(ray.direction.normalized * bulletForce, ForceMode.VelocityChange);
         * }   */
        if (Input.GetKeyDown(KeyCode.F))
        {
            //toggleDead();
            //myRagController.ragdoll.RepairBones();
            ragdoll.gameObject.SetActive(true);
            animatedM.gameObject.SetActive(false);

            //nav.enabled = false;
            // myRagController.GoRagdoll("manual");
            myRagController.GoRagdoll("");
            logicaPer.tirado         = true;
            logicaPer.armaDisparo    = false;
            refrescoCaido            = tiempo + 4f;
            logicaPer.rb.isKinematic = true;
            logicaPer.rb.isKinematic = false;
        }
        if ((controles.aButton || controles.spacebar) && logicaPer.tirado && !myRagController.isGettingUp && logicaPer.ragdollSuelo && refrescoCaido <= tiempo)
        {
            //toggleDead();
            //myRagController.ragdoll.RepairBones();
            //myRagController.StartGetUp();
            animatedM.transform.position = hips.transform.position;
            ragdoll.gameObject.SetActive(false);
            animatedM.gameObject.SetActive(true);
            //nav.enabled = true;
            //myRagController.ragdoll.RepairBones();
            //myRagController.GetUpImmediate();
            myRagController.StartGetUp();

            logicaPer.x = 0;
            logicaPer.y = 0;
            logicaPer.Move();
            logicaPer.puedoMoverme = false;
            logicaPer.anim.SetBool("tocarSuelo", true);
            //logicaPer.refrescoLevantarse = logicaPer.setCooldown(2.5f);
        }
    }
        void UpdateLoop()
        {
            if (ragdollController.state == RagdollControllerState.Animated)
            {
                if (characterMovement.freeFall)
                {
                    ragdollController.GoRagdoll(" free fall ");
                }
            }

            // CheckCameraTarget();


            // characterMovement.preventUpwardsMotion = ragdollController.state == RagdollControllerState.Falling;

            /*
             *                  skip moving the character transform if we're completely ragdolled,
             *  or waiting to reorient the main transform through the ragdoll controller
             */
            characterMovement.enableMovement = ragdollController.state != RagdollControllerState.Ragdolled && ragdollController.state != RagdollControllerState.TeleportMasterToRagdoll;
            if (!characterMovement.enableMovement)
            {
                characterMovement.SetMoveDelta(Vector3.zero);
                characterMovement.SetRotationDelta(Vector3.zero);
            }

            /*
             *      when animated or blending to animation
             *      use character controller movement
             *
             *      it has less step offset jitter than the normal transform movement
             *      especially when getting up
             */

            // on start blend to anim:
            // usePhysicsController = true

            // if (ragdollController.state == RagdollControllerState.Animated || ragdollController.state == RagdollControllerState.BlendToAnimated) {
            //  characterMovement.usePhysicsController = true;

            // }
            // else {

            /*
             *      when falling
             *
             *      use normal transform stuff (dont want the character controller collisions messing stuff up)
             *      for falling /calculating fall ( we need all exterion collisions to reach ragdol bones)
             *      and teh characer chontroller acts as a 'protective shell' when it's enabled
             */

            // on start fall (on ragdoll)
            // usePhysicsController = false

            //     characterMovement.usePhysicsController = false;
            // }

            //cehck if we started getting up
            // if (ragdollController.state == RagdollControllerState.BlendToAnimated) {
            //  //set zero speed
            //  if (movementController.speed != 0) {

            //         movementController.speed = 0;
            //  }
            // }

            //set the ragdolls fall speed based on our speed
            ragdollController.SetFallSpeed(movementController.speed == 0 ? idleFallSpeed : (movementController.speed == 1 ? walkFallSpeed : runFallSpeed));
        }