Beispiel #1
0
    private bool FindInnerCorner(PlayerController player, Vector3 dir, out LedgeInfo ledgeInfo)
    {
        Vector3 castFrom = player.transform.position
                           + Vector3.up * (player.HangUpOffset - ledgeDetector.MinDepth)
                           - player.transform.forward * 0.2f;

        if (ledgeDetector.FindLedgeAtPoint(castFrom, dir, 1f, 0.2f, out ledgeInfo))
        {
            return(true);
        }

        return(false);
    }
Beispiel #2
0
    private void AutoLedgeCheck(PlayerController player)
    {
        Vector3 startPos = player.transform.position + Vector3.up * player.CharControl.height;

        // If Lara's position changes too fast, can miss ledges
        float deltaH = Mathf.Max(Mathf.Abs(player.transform.position.y - lastPos.y), 0.12f);

        LedgeInfo ledgeInfo;

        if (player.AutoLedgeTarget && ledgeDetector.FindLedgeAtPoint(startPos, player.transform.forward, 0.25f, deltaH, out ledgeInfo))
        {
            grabPoint   = ledgeInfo.Point - player.transform.forward * player.HangForwardOffset;
            grabPoint.y = ledgeInfo.Point.y - player.HangUpOffset;

            player.transform.position = grabPoint;
            Quaternion ledgeRot = Quaternion.LookRotation(ledgeInfo.Direction, Vector3.up);
            player.transform.rotation = Quaternion.Euler(0f, ledgeRot.eulerAngles.y, 0f);

            player.Anim.SetTrigger("Grab");

            if (ledgeInfo.Type == LedgeType.Free)
            {
                player.StateMachine.GoToState <Freeclimb>();
            }
            else
            {
                player.StateMachine.GoToState <Climbing>();
            }

            return;
        }

        lastPos = player.transform.position;
    }
Beispiel #3
0
    private void CheckForClimbOut(PlayerController player)
    {
        LedgeInfo ledgeInfo;

        if (ledgeDetector.FindLedgeAtPoint(
                player.transform.position + Vector3.up * player.CharControl.height,
                player.transform.forward, player.CharControl.radius + 0.1f, 0.2f, out ledgeInfo))
        {
            player.Anim.SetTrigger("ClimbOut");
            isClimbingUp = true;

            player.UseRootMotion = false;

            player.CamControl.PivotOnPivot();

            player.transform.position = ledgeInfo.Point
                                        - (ledgeInfo.Direction * 0.54f)
                                        - Vector3.up * 1.9f;
            player.transform.rotation = Quaternion.LookRotation(ledgeInfo.Direction, Vector3.up);
        }
    }
Beispiel #4
0
    private CornerType CheckCorner(PlayerController player, Vector3 dir)
    {
        if (right == 0f)
        {
            return(CornerType.Continue);
        }

        float     upOffset = player.CharControl.height * 0.75f;
        LedgeInfo ledgeInfo;

        // Tests if something is in way of dir
        Vector3 start = player.transform.position + (Vector3.up * upOffset) - (player.transform.forward * 0.15f);

        if (!Physics.Raycast(start, dir, 0.4f))
        {
            // Test for continue as usual
            start = player.transform.position + (Vector3.up * upOffset) + dir * 0.4f;

            bool normalLedge = ledgeDetector.FindLedgeAtPoint(start, player.transform.forward, 0.6f, 0.2f, out ledgeInfo) &&
                               ledgeInfo.Type == LedgeType.Free;

            if (normalLedge)
            {
                return(CornerType.Continue);
            }

            // Test for stopping cause end of freeclimb
            if (Physics.Raycast(start, player.transform.forward, 0.6f))
            {
                return(CornerType.Stop);
            }

            // Test for out cornering
            start = player.transform.position + (Vector3.up * upOffset) + dir * 0.4f
                    + player.transform.forward * 0.52f;

            bool ledgeOutThere = ledgeDetector.FindLedgeAtPoint(start, -dir, 0.5f, 0.2f, out ledgeInfo) &&
                                 ledgeInfo.Type == LedgeType.Free;

            if (ledgeOutThere)
            {
                return(CornerType.Out);
            }

            // There is an out corner but its not climbable
            return(CornerType.Stop);
        }
        else
        {
            start = player.transform.position + (Vector3.up * upOffset) - (player.transform.forward * 0.15f);

            // Something is either blocking or we have to climb inwards
            bool ledgeThere = ledgeDetector.FindLedgeAtPoint(start, dir, 0.4f, 0.2f, out ledgeInfo) &&
                              ledgeInfo.Type == LedgeType.Free;

            if (ledgeThere)
            {
                return(CornerType.In);
            }

            // There is an in non-climbable corner
            return(CornerType.Stop);
        }
    }
Beispiel #5
0
    public override void Update(PlayerController player)
    {
        AnimatorStateInfo animState = player.Anim.GetCurrentAnimatorStateInfo(0);

        if (goingToClimb)
        {
            player.UseRootMotion = true;
            if (animState.IsName("HangLoop"))
            {
                player.StateMachine.GoToState <Climbing>();
            }

            return;
        }

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

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

        if (player.transform.position.y >
            (DPipe.CURRENT_DPIPE.transform.position.y
             + DPipe.CURRENT_DPIPE.SolidCollider.size.y - 2.24f))
        {
            bool noRootMotion = player.Anim.GetCurrentAnimatorStateInfo(0).IsName("DPipeUp") ||
                                player.Anim.GetCurrentAnimatorStateInfo(0).IsName("DPipeUpStop") ||
                                player.Anim.GetCurrentAnimatorStateInfo(0).IsName("DPipeUpStopM");
            player.Anim.applyRootMotion = !noRootMotion;

            forward = Mathf.Clamp(forward, -1f, 0f);
        }
        else if (player.transform.position.y < DPipe.CURRENT_DPIPE.transform.position.y + 1f)
        {
            forward = Mathf.Clamp01(forward);
        }

        if (right > 0.1f && animState.IsName("DPipeIdle"))
        {
            if (ledgeDetector.FindLedgeAtPoint(player.transform.position + Vector3.up * 2.24f + player.transform.right * 1f,
                                               player.transform.forward, 0.2f, 0.2f))
            {
                player.Anim.SetTrigger("OffRight");
                goingToClimb = true;
                return;
            }
        }

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

        player.transform.position = Vector3.Lerp(player.transform.position,
                                                 new Vector3(DPipe.CURRENT_DPIPE.transform.position.x - (player.transform.forward.x * 0.26f),
                                                             player.transform.position.y,
                                                             DPipe.CURRENT_DPIPE.transform.position.z - (player.transform.forward.z * 0.26f)),
                                                 5f * Time.deltaTime);
        player.transform.rotation = Quaternion.Lerp(player.transform.rotation,
                                                    Quaternion.LookRotation(DPipe.CURRENT_DPIPE.transform.forward), 5f * Time.deltaTime);
    }