Exemple #1
0
    void CheckClimbViability()
    {
        //Raycast below feet of player to see when done,
        //raycast top of climable object?? If lvl designer doesnt use it well.

        RaycastHit hit;
        Ray        ray = new Ray(new Vector3(transform.position.x, transform.position.y, transform.position.z), transform.forward);

        Debug.DrawRay(new Vector3(transform.position.x, transform.position.y, transform.position.z), transform.forward);
        Debug.DrawRay(transform.position, transform.up, Color.red);



        if (Physics.Raycast(ray, out hit) && m_psm.GetPlayerState(true) == scr_PSM.Playerstate.state_airborne && m_rgd.velocity.y < 0)
        {
            if (hit.collider.tag == "climbable")
            {
                if (Vector3.Distance(hit.point, transform.position) < 2)
                {
                    if (hit.collider.gameObject.transform.position.y + hit.collider.bounds.extents.y - transform.position.y < m_ClimbingLenght)
                    {
                        ClimbObject(hit.collider.gameObject, hit);
                    }
                }
            }
        }
    }
Exemple #2
0
    public void Move(Vector3 move, bool crouch, bool jump, bool sliding, bool climbing, Vector3 lookPos, bool aim)
    {
        // convert the world relative moveInput vector into a local-relative
        // turn amount and forward amount required to head in the desired
        // direction.

        if (move.magnitude > 1f)
        {
            move.Normalize();
        }
        move = transform.InverseTransformDirection(move);
        CheckGroundStatus();
        move                     = Vector3.ProjectOnPlane(move, m_GroundNormal);
        m_TurnAmount             = Mathf.Atan2(move.x, move.z);
        m_ForwardAmount          = move.z;
        m_Left                   = move.x;
        this.isAiming            = aim;
        this.isSliding           = sliding;
        this.currentLookPosition = lookPos;
        this.isClimbing          = climbing;
        if (!isAiming && m_PSM.GetPlayerState(true) == scr_PSM.Playerstate.state_grounded)
        {
            ApplyExtraTurnRotation();
        }
        else if (isAiming)
        {
            // m_Player.transform.forward = Camera.main.transform.forward;
            //
            m_Player.transform.forward = new Vector3(Camera.main.transform.forward.x, m_Player.transform.forward.y, Camera.main.transform.forward.z);
        }
        Sliding();
        // control and velocity handling is different when grounded and airborne:
        if (m_IsGrounded)
        {
            HandleGroundedMovement(crouch, jump);
            m_PSM.SetPlayerState(scr_PSM.Playerstate.state_grounded);
            m_PSM.SetPlayerPose(scr_PSM.PlayerPose.pose_running);
        }
        else if (m_PSM.GetPlayerPose(true) != scr_PSM.PlayerPose.pose_wallclimbing)
        {
            HandleAirborneMovement();
            m_PSM.SetPlayerState(scr_PSM.Playerstate.state_airborne);
        }
        ScaleCapsuleForCrouching(crouch);
        PreventStandingInLowHeadroom();
        JumpHandler();
        // send input and other state parameters to the animator
        UpdateAnimator(move);
    }