Exemplo n.º 1
0
    private void Crouch()
    {
        Debug.Log("Start crouching");

        IsCrouching = true;
        characterController.height = 1;
        Vector3 center = characterController.center;

        center.y = 0.5f;
        characterController.center = center;
        Vector3 direction = new Vector3(Horizontal, 0, Vertical).normalized;

        //if walking while crouching change the hitbox
        if (direction.magnitude == 0)
        {
            return;
        }

        characterController.height = 1.2f;
        center.y = 0.6f;
        characterController.center = center;

        OnCrouch?.Invoke(this, new OnCrouchEventArgs {
            IsCrouching = IsCrouching
        });
    }
Exemplo n.º 2
0
    private void CancelCrouching()
    {
        Debug.Log("Stop crouching");

        IsCrouching = false;
        characterController.height = 1.5f;
        var center = characterController.center;

        center.y = 0.8f;
        characterController.center = center;

        OnCrouch?.Invoke(this, new OnCrouchEventArgs {
            IsCrouching = IsCrouching
        });
    }
 public virtual void Crouch()
 {
     if (isGrounded && !actions)
     {
         if (isCrouching && CanExitCrouch())
         {
             isCrouching = false;
         }
         else
         {
             isCrouching = true;
             OnCrouch.Invoke();
         }
     }
 }