Exemplo n.º 1
0
    public override void Update(PlayerController player)
    {
        AnimatorStateInfo animState = player.Anim.GetCurrentAnimatorStateInfo(0);

        right   = Input.GetAxis(player.Inputf.horizontalAxis);
        forward = Input.GetAxis(player.Inputf.verticalAxis);

        if (isInCornering || isOutCornering)
        {
            if (animState.IsName("FreeclimbCornerInR") || animState.IsName("FreeclimbCornerInL") ||
                animState.IsName("FreeclimbCornerOutR") || animState.IsName("FreeclimbCornerOutL"))
            {
                player.UseRootMotion = true;
                return;
            }
            else if (animState.IsName("FreeclimbIdle"))
            {
                isOutCornering = isInCornering = false;
            }
            else
            {
                return;
            }
        }
        else if (isClimbingUp)
        {
            if (animState.IsName("Idle"))
            {
                player.Anim.SetBool("isClimbingUp", false);
                player.StateMachine.GoToState <Locomotion>();
            }
            return;
        }

        if (Input.GetKeyDown(player.Inputf.crouch))
        {
            player.StopMoving();
            player.Anim.SetTrigger("LetGo");
            player.StateMachine.GoToState <InAir>();
            return;
        }

        Vector3 ledgeCheckStart = player.transform.position + 1.6f * Vector3.up;

        if (forward > 0.1f && !Physics.Raycast(ledgeCheckStart - player.transform.forward * 0.2f, player.transform.forward, 1f))
        {
            Vector3 tryClimbTo = ledgeCheckStart + player.transform.forward * player.CharControl.radius * 2f;
            if (UMath.CanFitInSpace(tryClimbTo, player.CharControl.height, player.CharControl.radius))
            {
                isClimbingUp = true;
                player.Anim.SetBool("isClimbingUp", true);
                return;
            }
        }

        HandleCorners(player);
        AdjustPosition(player, animState);
        StopClimbingIntoWalls(player);

        player.Anim.SetFloat("Forward", forward);
        player.Anim.SetFloat("Right", right);
        player.Anim.SetBool("isOutCorner", isOutCornering);
        player.Anim.SetBool("isInCorner", isInCornering);
    }
Exemplo n.º 2
0
    public override void Update(PlayerController player)
    {
        AnimatorStateInfo      animState = player.Anim.GetCurrentAnimatorStateInfo(0);
        AnimatorTransitionInfo transInfo = player.Anim.GetAnimatorTransitionInfo(0);

        right = Input.GetAxisRaw(player.Inputf.horizontalAxis);

        if (isInCornering || isOutCornering)
        {
            if (animState.IsName("InCornerLeft") || animState.IsName("CornerLeft") ||
                animState.IsName("CornerRight") || animState.IsName("InCornerRight"))
            {
                player.UseRootMotion = true;

                MatchTargetWeightMask mask = new MatchTargetWeightMask(Vector3.one, 1f);
                player.Anim.MatchTarget(cornerTargetPosition, cornerTargetRotation, AvatarTarget.Root, mask, 0f, 1f);

                return;
            }
            else if (animState.IsName("HangLoop"))
            {
                isOutCornering = isInCornering = false;

                player.UseRootMotion = true;
            }
            else
            {
                return;
            }
        }
        else if (isClimbingUp)
        {
            if (animState.IsName("Idle") || transInfo.IsName("ClimbUp -> Idle"))
            {
                player.StateMachine.GoToState <Locomotion>();
            }

            return;
        }

        if (Input.GetKeyDown(player.Inputf.crouch))
        {
            LetGo(player);
            return;
        }

        AdjustPosition(player);

        if (right != 0f)
        {
            LookForCorners(player);
        }

        player.Anim.SetFloat("Right", right);

        player.Anim.SetBool("isOutCorner", isOutCornering);
        player.Anim.SetBool("isInCorner", isInCornering);

        // Test for climbing up key hold times
        if (animState.IsName("HangLoop"))
        {
            if (Input.GetKey(player.Inputf.jump) && jumpHeldFor < HANDSTAND_HOLD_TIME)
            {
                jumpHeldFor += Time.deltaTime;
            }
            else if (Input.GetKeyUp(player.Inputf.jump) || jumpHeldFor >= HANDSTAND_HOLD_TIME)
            {
                Vector3 tryClimbTo = ledgeInfo.Point + player.transform.forward * player.CharControl.radius;
                if (UMath.CanFitInSpace(tryClimbTo, player.CharControl.height, player.CharControl.radius))
                {
                    ClimbUp(player);
                }
            }
        }
    }