Example #1
0
    void MoveInCover()
    {
        characterController.detectCollisions = false;
        float axis = Input.GetAxis("Horizontal");

        Debug.Log(axis);
        if (axis > 0)
        {
            //facingRight = false;
            coverScript.isFacingRight          = true;
            animator.runtimeAnimatorController = coverScript.CoverOvveride();
        }
        else if (axis < 0)
        {
            //facingRight = true;
            coverScript.isFacingRight          = false;
            animator.runtimeAnimatorController = coverScript.LeftCoverOvveride();
        }
        if (axis != 0)
        {
            animator.SetBool("IsMoving", true);
        }
        else
        {
            animator.SetBool("IsMoving", false);
        }

        RaycastHit hit;
        //Vector3 v = transform.position + new Vector3(0, 0.1f, 0)+axis*transform.right;
        Vector3 v = transform.position + new Vector3(0, 0.1f, 0) + (axis > 0 ? transform.right * 1.1f :-transform.right);

        Debug.DrawLine(v, v + transform.forward * 1, Color.red, 5f);
        if (Physics.Raycast(v, v + transform.forward * 1, out hit, coverScript.coverDetectionDist, coverScript.GetCoverLayerMask()))
        {
            Vector3 moveDirection = axis * coverScript.GetTangent();
            //transform.Translate(moveDirection * coverScript.moveInCoverSpeed, Space.World);
            characterController.Move(moveDirection * coverScript.moveInCoverSpeed);
        }
    }