전투 시스템 구현

Player stamina

  • stamina bar는 stamina를 시각화하기 위해 일시적으로 구현해 놓은 ui이다.
  • player의 stamina는 각각 '소모'하는 상태와 '회복'하는 상태로 나뉠 수 있다.
  • '소모'하는 상태는 '달리기', '회피', '점프', '공격'(무기마다 상이), '점프 공격, '방어 중 피격'이다.
  • '회복'하는 상태는 '걷기', '기본', '패링'이다.
  • '달리기'와 '패링을'을 제외한 나머지 회복 상태는 초당 소모 및 회복이므로 staminavalue * Time.deltaTime로 계산되어져야 한다.
  • 결국 stamina를 소모하거나 회복하는 것은 player 현재의 stamina에서 그 만큼 더하거나 빼는 것이므로 소모, 회복 각각에 대한 메소드를 생성 후 소모량 및 회복량을 parameter로 받아왔다.
public static void ConsumeStamina(float consumption)
{
    if(_currentPlayerST > 0)
    {
        _currentPlayerST -= consumption;
        _currentPlayerST = Mathf.Clamp(_currentPlayerST, 0, _playerMaxStamina);
    }
}
public static void RecoveryStamina(float recoveryQuantity)
{
    if (_currentPlayerST < _playerMaxStamina)
    {
        _currentPlayerST += recoveryQuantity;
        _currentPlayerST = Mathf.Clamp(_currentPlayerST, 0, _playerMaxStamina);
    }
}
  • clamp는 stamina를 float 값을 설정하였기 때문에 보정을 해주었다.

  • 해당 동작이 들어갈 때 혹은 실행 중에 소모 및 회복을 구현하기 위해 state behaviour를 사용하였다.

  • 하지만 예상치 못한 문제점이 발생했다.
    stamina error

  • 동작을 처음 실행할 때만 stamina가 소모되는 animation 에서 소모량 만큼 소모되고 일시적으로 회복이 되는 현상이 발생했다.

  • 이는 animation transition 기간 안에 발생한 것으로 animation transition 값을 0으로 바꾸었을 때, 그 현상이 사라졌다.

profile
NEWB!

0개의 댓글