Develop_Log

[TrobleShooting] ww로 달리기 구현

리네엔 2024. 10. 24. 22:20
  • 블레이드 소울처럼 ww키로 달리거나
  • shift를 눌러 달릴 수 있도록 구현하고 싶었음.


  • 결과

처음 시도

  • W를 MultiTab / Tap Count 2로 실행함 - 안됨

    디버깅

  • ww를 누를때 두번째 w를 빠르게 떼야 isRun이 true가 됨을 알게됨.

제약사항

  • ww 를 두번째 w를 꾹 눌러 계속 이동할 수 있게 해야 했음.
  • leftshift도 누르고 있을 때 run, 떼면 다시 걷게 해야 함.
  • InputAction.CallbackContext 에서 어떤 키가 눌린 건지는 감별 할 수 없음

해결 방법

  • InputAction.CallbackContext에서 지금 인터렉션이 어떤 인터렉션인지는 알 수 있음
    • context.interaction is MultiTapInteraction
  • 이를 활용해서 multitab의 tap count를 1로 하고, bool 변수 두개를 사용하여 ww 달리기를 구현함
    public void OnRun(InputAction.CallbackContext context)
    {
      if(context.interaction is MultiTapInteraction)
      {
          if (context.performed)
          {
              _firstTabSuccess = true;
          }
          if (context.canceled)
          {
              if (_firstTabSuccess)
              {
                  OnRunning();
                  _isRunning = true;
              }
          }
      }
      else
      {
          if (context.performed)
          {
              OnRunning();
          }
          if (context.canceled)
          {
              OnStopRunning();
          }
      }
    }
  • ww로 뛰면 뛰기를 멈출 수가 없는 문제가 있음.
    • move 이벤트에서 _isRunning를 검사해 cancled될 때 뛰기를 멈춰줌
      public void OnMove(InputAction.CallbackContext context)
      {
        OnMoveing(context.ReadValue<Vector2>());
        if (_isRunning)
        {
            _firstTabSuccess = false;
            _isRunning = false;
            OnStopRunning();
        }
      }

알게 된 것

  • 이전 트러블 슈팅에서 multitab이 performed가 두번 호출되면 실행되는 줄 알았는데, 그게 아니라 설정된 시간내에 두번 눌렀다 "떼기"가 완료되야 호출되는 것이었다.