Esempio n. 1
0
        void UseLadder()
        {
            if (!isUsingLadder)
            {
                return;
            }

            // update the base layer to know what animations are being played
            tpInput.cc.LayerControl();
            tpInput.cc.ActionsControl();
            // update camera movement
            tpInput.CameraInput();

            // go up or down
            tpInput.cc.input.y = tpInput.verticallInput.GetAxis();
            speed = Mathf.Clamp(tpInput.cc.input.y, -1f, 1f);
            tpInput.cc.animator.SetFloat("InputVertical", speed, 0.25f, Time.deltaTime);

            // enter ladder behaviour
            //if (ladderAction != null && ladderAction.matchTarget != null)
            {
                if (tpInput.cc.baseLayerInfo.IsName("EnterLadderTop") || tpInput.cc.baseLayerInfo.IsName("EnterLadderBottom"))
                {
                    // disable ingame hud
                    if (ladderActionTemp != null)
                    {
                        ladderActionTemp.OnPlayerExit.Invoke();
                    }

                    if (ladderActionTemp.useTriggerRotation)
                    {
                        // smoothly rotate the character to the target
                        transform.rotation = Quaternion.Lerp(transform.rotation, ladderActionTemp.matchTarget.transform.rotation, tpInput.cc.animator.GetCurrentAnimatorStateInfo(0).normalizedTime);
                    }

                    if (ladderActionTemp.matchTarget != null)
                    {
                        if (debugMode)
                        {
                            Debug.Log("Match Target...");
                        }
                        // use match target to match the Y and Z target
                        tpInput.cc.MatchTarget(ladderActionTemp.matchTarget.transform.position, ladderActionTemp.matchTarget.transform.rotation, AvatarTarget.Root, new MatchTargetWeightMask(new Vector3(1, 1, 1), 0), ladderActionTemp.startMatchTarget, ladderActionTemp.endMatchTarget);
                    }
                }
            }

            // exit ladder behaviour
            isExitingLadder = tpInput.cc.baseLayerInfo.IsName("ExitLadderTop") || tpInput.cc.baseLayerInfo.IsName("ExitLadderBottom");

            if (isExitingLadder && tpInput.cc.baseLayerInfo.normalizedTime >= 0.8f)
            {
                // after playing the animation we reset some values
                ResetPlayerSettings();
            }
        }
        void UseLadder()
        {
            if (!isUsingLadder)
            {
                return;
            }

            // update the base layer to know what animations are being played
            tpInput.cc.AnimatorLayerControl();
            tpInput.cc.ActionsControl();
            // update camera movement
            tpInput.CameraInput();

            // go up or down
            speed = verticallInput.GetAxis();
            tpInput.cc.animator.SetFloat(vAnimatorParameters.InputVertical, speed, 0.1f, Time.deltaTime);
            if (speed >= 0.05f || speed <= -0.05f)
            {
                tpInput.cc.animator.speed = Mathf.Lerp(tpInput.cc.animator.speed, currentClimbSpeed, 2f * Time.deltaTime);
            }
            else
            {
                tpInput.cc.animator.speed = Mathf.Lerp(tpInput.cc.animator.speed, 1f, 2f * Time.deltaTime);
            }

            // increase speed by input and consume stamina
            if (fastClimbInput.GetButton() && tpInput.cc.currentStamina > 0)
            {
                currentClimbSpeed = fastClimbSpeed;
                StaminaConsumption();
            }
            else
            {
                currentClimbSpeed = climbSpeed;
            }

            // enter ladder behaviour
            if (tpInput.cc.baseLayerInfo.IsName("EnterLadderTop") || tpInput.cc.baseLayerInfo.IsName("EnterLadderBottom") && !tpInput.cc.animator.IsInTransition(0))
            {
                tpInput.cc.DisableGravityAndCollision();              // disable gravity & turn collision trigger
                // disable ingame hud
                if (ladderActionTemp != null)
                {
                    ladderActionTemp.OnPlayerExit.Invoke();
                }

                if (ladderActionTemp.useTriggerRotation)
                {
                    if (debugMode)
                    {
                        Debug.Log("Rotating to target...");
                    }
                    EvaluateToRotation(ladderActionTemp.enterRotationCurve, ladderActionTemp.matchTarget.transform.rotation, tpInput.cc.baseLayerInfo.normalizedTime);
                }

                if (ladderActionTemp.matchTarget != null)
                {
                    if (transform.parent != ladderActionTemp.targetCharacterParent)
                    {
                        transform.parent = ladderActionTemp.targetCharacterParent;
                    }

                    if (debugMode)
                    {
                        Debug.Log("Match Target to enter...");
                    }

                    EvaluateToPosition(ladderActionTemp.enterPositionXZCurve, ladderActionTemp.enterPositionYCurve, ladderActionTemp.matchTarget.position, tpInput.cc.baseLayerInfo.normalizedTime);
                }
            }

            // exit ladder behaviour
            isExitingLadder = tpInput.cc.baseLayerInfo.IsName("ExitLadderTop") || tpInput.cc.baseLayerInfo.IsName("ExitLadderBottom") || tpInput.cc.baseLayerInfo.IsName("QuickExitLadder");

            if (isExitingLadder)
            {
                tpInput.cc.animator.speed = 1;

                if (ladderActionTemp.exitMatchTarget != null && !tpInput.cc.baseLayerInfo.IsName("QuickExitLadder"))
                {
                    if (debugMode)
                    {
                        Debug.Log("Match Target to exit...");
                    }

                    EvaluateToPosition(ladderActionTemp.exitPositionXZCurve, ladderActionTemp.exitPositionYCurve, ladderActionTemp.exitMatchTarget.position, tpInput.cc.baseLayerInfo.normalizedTime);
                }
                var newRot = new Vector3(0, tpInput.animator.rootRotation.eulerAngles.y, 0);
                EvaluateToRotation(ladderActionTemp.exitRotationCurve, Quaternion.Euler(newRot), tpInput.cc.baseLayerInfo.normalizedTime);

                if (tpInput.cc.baseLayerInfo.normalizedTime >= 0.8f)
                {
                    // after playing the animation we reset some values
                    ResetPlayerSettings();
                }
            }
        }
Esempio n. 3
0
        protected virtual void UsingLadder()
        {
            if (!isUsingLadder)
            {
                return;
            }

            // update the base layer to know what animations are being played
            tpInput.cc.AnimatorLayerControl();
            tpInput.cc.ActionsControl();
            // update camera movement
            tpInput.CameraInput();

            // go up or down
            speed = verticallInput.GetAxis();
            tpInput.cc.animator.SetFloat(vAnimatorParameters.InputVertical, speed, 0.1f, Time.deltaTime);
            if (speed >= 0.05f || speed <= -0.05f)
            {
                tpInput.cc.animator.speed = Mathf.Lerp(tpInput.cc.animator.speed, currentClimbSpeed, 2f * Time.deltaTime);
            }
            else
            {
                tpInput.cc.animator.speed = Mathf.Lerp(tpInput.cc.animator.speed, 1f, 2f * Time.deltaTime);
            }

            // increase speed by input and consume stamina
            if (fastClimbInput.GetButton() && tpInput.cc.currentStamina > 0)
            {
                currentClimbSpeed = fastClimbSpeed;
                StaminaConsumption();
            }
            else
            {
                currentClimbSpeed = climbSpeed;
            }

            // enter ladder behaviour
            var _inEnterLadderAnimation = tpInput.cc.baseLayerInfo.IsName("EnterLadderTop") || tpInput.cc.baseLayerInfo.IsName("EnterLadderBottom") && !tpInput.cc.animator.IsInTransition(0);

            if (_inEnterLadderAnimation)
            {
                this.inEnterLadderAnimation = true;

                tpInput.cc.DisableGravityAndCollision();              // disable gravity & turn collision trigger
                // disable ingame hud
                if (currentLadderAction != null)
                {
                    currentLadderAction.OnPlayerExit.Invoke();
                }

                if (currentLadderAction.useTriggerRotation)
                {
                    if (debugMode)
                    {
                        Debug.Log("Rotating to target..." + currentLadderAction.name + "_" + currentLadderAction.transform.parent.gameObject.name);
                    }
                    EvaluateToRotation(currentLadderAction.enterRotationCurve, currentLadderAction.matchTarget.transform.rotation, tpInput.cc.baseLayerInfo.normalizedTime);
                }

                if (currentLadderAction.matchTarget != null)
                {
                    if (transform.parent != currentLadderAction.targetCharacterParent)
                    {
                        transform.parent = currentLadderAction.targetCharacterParent;
                    }

                    if (debugMode)
                    {
                        Debug.Log("Match Target to Enter..." + currentLadderAction.name + "_" + currentLadderAction.transform.parent.gameObject.name);
                    }

                    EvaluateToPosition(currentLadderAction.enterPositionXZCurve, currentLadderAction.enterPositionYCurve, currentLadderAction.matchTarget.position, tpInput.cc.baseLayerInfo.normalizedTime);
                }
            }

            if (!_inEnterLadderAnimation && inEnterLadderAnimation)
            {
                enterLadderStarted     = false;
                inEnterLadderAnimation = false;
            }
            TriggerExitLadder();
        }