UnrealEngine - HitStop

2025. 6. 17. 15:27·Unreal Engine

전투 게임에 있어서 가장 중요한 부분중에 하나가 타격감이다.

 

여러가지 정보를 찾다가 아래 영상을 통해 Hit Stop이라는 것을 접하게 되었고 게임에 적용해 보게 되었다.

https://youtu.be/IL9j4NchTvA?si=MM6F7kJEw7RysZRI&t=1951

 

 

1. 기능 구현


가장 간단한 방식으로는 해당 시점에 시간을 느리게 만들어주는 방식이 존재한다.

 

코드를 보면

  • SetGlobalTimeDilation을 통해 World의 시간을 지연시켜서 느려지도록 하는 방식이다.
  • 단순히 싱글플레이 게임에 있어서는 아래와 같은 방식을 사용해도 문제가 없을것이지만, 현재 게임은 멀티플레이 게임이기 때문에 멀티캐스트를 통해서 시간 지연하는 함수를 사용하기 때문에 월드에 존재하는 모든 플레이어들의 시간이 느려지는 문제가 있다.
void AGS_Guardian::MulticastRPCApplyHitStop_Implementation()
{
	if (GetWorld() && GetWorld()->GetNetMode() == NM_DedicatedServer)
	{
		return;	
	}

	UGameplayStatics::SetGlobalTimeDilation(GetWorld(), HitStopTimeDilation);
	GetWorld()->GetTimerManager().SetTimer(HitStopTimerHandle, this, &AGS_Guardian::EndHitStop, HitStopDurtaion*HitStopTimeDilation, false);
}

void AGS_Guardian::EndHitStop()
{
	UGameplayStatics::SetGlobalTimeDilation(GetWorld(), 1.f);
}

 

 

2. 트러블슈팅


위에서 언급한 문제를 해결하기 위해 CustomTimeDelation을 사용하였다.

https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Engine/GameFramework/AActor/CustomTimeDilation

  • 해당 기능은 각 액터가 가진 기능으로
  • 액터 각각의 시간을 지연시키는 기능이기 때문에 멀티플레이에 있어서 해당 기능을 사용하는 것이 더 좋은 방식이다.

새롭게 구현된 코드는 아래와 같다.

  • 데미지를 입은 캐릭터를 매개변수로 넣어준 후 멀티캐스트를 통해 HitStop을 적용해준다.
  • 이후에 "타이머 델리게이트"를 통해서 EndHitStop 함수에 데미지를 입은 캐릭터를 매개변수로 넣어주었다.
  • 추가적으로 CameraShake 기능을 추가하였다.
void AGS_Guardian::ApplyDamageToDetectedPlayer(const TSet<AGS_Character*>& DamagedCharacters, float PlusDamge)
{
	for (auto const& DamagedCharacter : DamagedCharacters)
	{
    	      ...
	      MulticastRPCApplyHitStop(DamagedCharacter);			
        
	}
}
void AGS_Guardian::MulticastRPCApplyHitStop_Implementation(AGS_Character* InDamagedCharacter)
{
	if (HasAuthority())
	{
		if (CameraShakeComponent)
		{
			CameraShakeComponent->PlayCameraShake(HitStopShakeInfo);
		}
	}
	if (!HasAuthority())
	{
		CustomTimeDilation = 0.1f;
		InDamagedCharacter->CustomTimeDilation = 0.1f;

		FTimerDelegate HitStopTimerDelegate;
		FTimerHandle HitStopTimerHandle;
        
		HitStopTimerDelegate.BindUFunction(this, FName("EndHitStop"), InDamagedCharacter);
		GetWorld()->GetTimerManager().SetTimer(HitStopTimerHandle, HitStopTimerDelegate, HitStopDurtaion, false);
	}
}

void AGS_Guardian::MulticastRPCEndHitStop_Implementation(AGS_Character* InDamagedCharacter)
{
	if (!HasAuthority())
	{
		CustomTimeDilation = 1.f;
		InDamagedCharacter->CustomTimeDilation = 1.f;
	}
}

 

결과 영상

  • 아래 두 화면 (공격자와 피격자) 의 캐릭터만 화면 흔들림과 시간 지연이 발생한다
  • 오른쪽 위 화면의 캐릭터는 시간지연 발생 x

 

'Unreal Engine' 카테고리의 다른 글

UE5 Issues - 파괴되는 Mesh  (2) 2025.06.18
UE5 Issues - 서버 & 클라이언트 로직  (0) 2025.06.15
UE5 Issues : 데디케이트 서버 UI에 관해  (0) 2025.06.12
Unreal Engine - 데디케이티드 서버 11 (콤보 공격 최적화)  (0) 2025.06.02
Unreal Engine - 데디케이티드 서버 10 (콤보 공격)  (0) 2025.05.30
'Unreal Engine' 카테고리의 다른 글
  • UE5 Issues - 파괴되는 Mesh
  • UE5 Issues - 서버 & 클라이언트 로직
  • UE5 Issues : 데디케이트 서버 UI에 관해
  • Unreal Engine - 데디케이티드 서버 11 (콤보 공격 최적화)
gbleem
gbleem
gbleem 님의 블로그 입니다.
  • gbleem
    gbleem 님의 블로그
    gbleem
  • 전체
    오늘
    어제
    • 분류 전체보기 (189)
      • Unreal Engine (73)
      • C++ (19)
      • 알고리즘(코딩테스트) (32)
      • TIL (60)
      • CS (4)
      • 툴 (1)
  • 블로그 메뉴

    • 홈
    • 카테고리
  • 링크

    • 과제용 깃허브
    • 깃허브
    • velog
  • 공지사항

  • 인기 글

  • 태그

    BFS
    character animation
    gamestate
    매크로 지정자
    map을 vector로 복사
    싱글턴
    템플릿
    cin함수
    Vector
    addonscreendebugmessage
    additive animation
    DP
    상속
    applydamage
    const
    motion matching
    enhanced input system
    blend pose
    C++
    actor 클래스
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
gbleem
UnrealEngine - HitStop
상단으로

티스토리툴바