Exemple #1
0
    public void SetCrouch(bool state)
    {
        if (state)
        {
            if (jump.IsGrounded())
            {
                isCrouching = true;
            }
        }
        else
        {
            if (!CheckIfColliderAbove())
            {
                isCrouching = false;
            }
        }

        if (isCrouching)
        {
            CameraObj.transform.localPosition = Vector3.Lerp(CameraObj.transform.localPosition, camera_crouchPos, Time.deltaTime / crouchStateSpeed);
            capsule.center = new Vector3(0, -0.5f, 0);
            capsule.height = 1;
        }
        else
        {
            CameraObj.transform.localPosition = Vector3.Lerp(CameraObj.transform.localPosition, camera_initPos, Time.deltaTime / crouchStateSpeed);

            capsule.center = Vector3.zero;
            capsule.height = 2;
        }
    }
    void Update()
    {
        locomotion.isRunning = Input.GetKeyDown(SprintKey) && jump.IsGrounded();

        locomotion.Move(new Vector2(
                            -Input.GetAxis("Vertical"),
                            Input.GetAxis("Horizontal")
                            ));

        if (Input.GetKeyDown(JumpKey))
        {
            jump.Jump();
        }
    }