예제 #1
0
    public override void OnEnter(PlayerController player)
    {
        if (ledgeInfo == null)
        {
            Debug.LogError("Autograbbing has no ledge info... you need to pass ledge info as context... going to in air");
            player.StateMachine.GoToState <InAir>();
            return;
        }

        player.UseGravity      = true;
        player.UseRootMotion   = false;
        player.GroundedOnSteps = false;

        player.MinimizeCollider();

        player.Anim.SetBool("isAutoGrabbing", true);

        player.ForceHeadLook = true;
        player.HeadLookAt    = ledgeInfo.Point;

        grabPoint   = ledgeInfo.Point - player.transform.forward * player.HangForwardOffset;
        grabPoint.y = ledgeInfo.Point.y - player.HangUpOffset;

        Vector3 calcGrabPoint;

        if (ledgeInfo.Type == LedgeType.Monkey || ledgeInfo.Type == LedgeType.HorPole)
        {
            calcGrabPoint = grabPoint - Vector3.up * 0.14f;
            targetRot     = player.transform.rotation;
        }
        else
        {
            calcGrabPoint = ledgeInfo.Point + player.GrabUpOffset * Vector3.down - ledgeInfo.Direction * player.GrabForwardOffset;
            Vector3 ledgeDir = ledgeInfo.Direction;
            ledgeDir.y = 0f;
            targetRot  = Quaternion.LookRotation(ledgeDir);
        }

        Vector3 velocityAdjusted = UMath.VelocityToReachPoint(player.transform.position,
                                                              calcGrabPoint,
                                                              player.RunJumpVel,
                                                              player.Gravity,
                                                              out grabTime);

        // So Lara doesn't do huge upwards jumps or snap when close
        if (grabTime < 0.3f || grabTime > 1.2f)
        {
            grabTime = Mathf.Clamp(grabTime, 0.4f, 1.2f);

            velocityAdjusted = UMath.VelocityToReachPoint(player.transform.position,
                                                          calcGrabPoint,
                                                          player.Gravity,
                                                          grabTime);
        }

        // Apply the correct velocity calculated
        player.ImpulseVelocity(velocityAdjusted);

        Debug.Log("Setting vel: " + velocityAdjusted);

        if (ledgeInfo.Collider != null)
        {
            initialColliderPos = ledgeInfo.Collider.transform.position;

            MovingPlatform moving = ledgeInfo.Collider.GetComponent <MovingPlatform>();

            if (moving != null)
            {
                // So Player aligns with ledge
                moving.AttachTransform(player.transform);
            }
        }

        timeTracker = Time.time;
    }
예제 #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;
        }

        // Adjustment for moving platforms
        RaycastHit hit;

        if (Physics.Raycast(player.transform.position + Vector3.up * (player.HangUpOffset - 0.1f), player.transform.forward, out hit, 1f, ~(1 << 8), QueryTriggerInteraction.Ignore))
        {
            if (hit.collider.CompareTag("MovingPlatform"))
            {
                MovingPlatform moving = hit.collider.GetComponent <MovingPlatform>();

                moving.AttachTransform(player.transform);
            }
        }

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

        AdjustPosition(player);

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

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

        if (Input.GetKey(player.Inputf.jump) && animState.IsName("HangLoop"))
        {
            if (ledgeDetector.CanClimbUp(player.transform.position, player.transform.forward))
            {
                ClimbUp(player);
            }
        }
    }