게임플레이 오디오 연동
발소리 시스템, Physical Surface 연동, 무기 사운드, 대사 시스템 구현
발소리 시스템
Physical Surface에 따라 다른 발소리를 재생하는 시스템
발소리는 게임 오디오에서 가장 빈번하게 재생되는 사운드입니다. Physical Surface(물리 표면 타입)를 감지하여 콘크리트, 잔디, 금속 등 재질에 맞는 사운드를 재생합니다.
void UFootstepComponent::PlayFootstep()
{
// 발 위치에서 아래로 라인 트레이스
FHitResult Hit;
FVector Start = GetOwner()->GetActorLocation();
FVector End = Start - FVector(0, 0, 100);
FCollisionQueryParams Params;
Params.bReturnPhysicalMaterial = true;
Params.AddIgnoredActor(GetOwner());
if (GetWorld()->LineTraceSingleByChannel(
Hit, Start, End, ECC_Visibility, Params))
{
// Physical Material에서 Surface Type 가져오기
EPhysicalSurface SurfaceType =
UPhysicalMaterial::DetermineSurfaceType(
Hit.PhysMaterial.Get());
// Surface에 맞는 사운드 선택
USoundBase* FootstepSound =
GetFootstepSoundForSurface(SurfaceType);
if (FootstepSound)
{
UGameplayStatics::PlaySoundAtLocation(
this, FootstepSound,
Hit.ImpactPoint,
FRotator::ZeroRotator,
1.0f, // Volume
FMath::RandRange(0.9f, 1.1f), // Pitch 랜덤
0.0f,
FootstepAttenuation,
FootstepConcurrency
);
}
}
}
USoundBase* UFootstepComponent::GetFootstepSoundForSurface(
EPhysicalSurface Surface)
{
switch (Surface)
{
case SurfaceType1: // Concrete
return ConcreteFootsteps[FMath::RandRange(0, 3)];
case SurfaceType2: // Grass
return GrassFootsteps[FMath::RandRange(0, 3)];
case SurfaceType3: // Metal
return MetalFootsteps[FMath::RandRange(0, 3)];
case SurfaceType4: // Wood
return WoodFootsteps[FMath::RandRange(0, 3)];
case SurfaceType5: // Water
return WaterFootsteps[FMath::RandRange(0, 3)];
default:
return DefaultFootsteps[FMath::RandRange(0, 3)];
}
}
MetaSounds를 사용하면, Physical Surface 타입을 Int 파라미터로 전달하고, MetaSound 내부에서 해당 값에 따라 Wave Array에서 적절한 샘플을 선택하도록 구현할 수 있습니다. 하나의 MetaSound Source로 모든 표면 타입을 처리합니다.
무기 사운드 시스템
발사, 충격, 탄피, 재장전 등 무기 오디오의 구조
무기 사운드 레이어 구조
| 레이어 | 사운드 | 위치 | 감쇠 |
|---|---|---|---|
| 발사음 (Shot) | 총구 화염 메인 사운드 | 총구 위치 | 대형 (8000cm+) |
| 메카니즘 | 기계 장치 작동음 | 무기 중심 | 소형 (1000cm) |
| 탄피 (Shell) | 탄피 배출 + 바닥 충돌 | 이젝션 포트 → 바닥 | 소형 (500cm) |
| 탄착 (Impact) | 표면별 충돌음 | 충돌 위치 | 중형 (3000cm) |
| 꼬리음 (Tail) | 환경 반사/잔향 | 발사 위치 (넓은 범위) | 초대형 (15000cm+) |
| 재장전 | 탄창 교체, 장전 사운드 | 무기 중심 | 소형 (1000cm) |
발사음의 "꼬리음"은 실내/외에 따라 달라야 합니다. 실내에서는 짧은 잔향, 야외에서는 긴 에코가 자연스럽습니다. 발사 시점에 레이캐스트로 환경을 감지하고, Indoor/Outdoor Tail 사운드를 선택하세요.
대사(Dialogue) 시스템
NPC 대사 재생, 큐 관리, 자막 연동
void UDialogueManager::PlayDialogue(
const FDialogueEntry& Entry)
{
// 이미 재생 중인 대사가 있으면 큐에 추가
if (bIsPlaying)
{
DialogueQueue.Enqueue(Entry);
return;
}
bIsPlaying = true;
// 대사 더킹 Mix 활성화
UGameplayStatics::PushSoundMixModifier(
this, DialogueDuckingMix);
// NPC 위치에서 3D 재생
if (Entry.Speaker)
{
DialogueAudioComp =
UGameplayStatics::SpawnSoundAttached(
Entry.DialogueSound,
Entry.Speaker->GetMesh(),
"head"); // 입 근처 소켓
}
// 자막 표시
if (SubtitleWidget)
{
SubtitleWidget->ShowSubtitle(
Entry.SpeakerName,
Entry.SubtitleText,
Entry.Duration);
}
// 재생 완료 콜백
DialogueAudioComp->OnAudioFinished.AddDynamic(
this,
&UDialogueManager::OnDialogueFinished);
}
void UDialogueManager::OnDialogueFinished()
{
// 큐에 다음 대사가 있으면 재생
FDialogueEntry NextEntry;
if (DialogueQueue.Dequeue(NextEntry))
{
PlayDialogue(NextEntry);
}
else
{
bIsPlaying = false;
UGameplayStatics::PopSoundMixModifier(
this, DialogueDuckingMix);
}
}
환경 앰비언스 시스템
Ambient Sound Actor와 동적 환경 사운드 관리
환경 앰비언스는 레벨에 Ambient Sound Actor를 배치하거나, Blueprint로 시간/날씨에 따라 동적으로 변경합니다.
| 배치 방식 | 방법 | 적합한 용도 |
|---|---|---|
| Ambient Sound Actor | 레벨에 직접 배치, Attenuation으로 범위 지정 | 물소리, 화로, 기계 장치 등 고정 위치 소스 |
| Audio Volume | 영역 기반 앰비언스 + 리버브 | 실내/외 전환, 지역별 배경 사운드 |
| Blueprint 동적 생성 | SpawnSoundAtLocation/Attached | 시간/날씨에 따라 변하는 환경음 |
풍부한 환경음은 3개 레이어로 구성합니다: 1) 베드(Bed) - 지속적인 배경음(바람, 도시 소음), 2) 디테일(Detail) - 간헐적인 점 음원(새소리, 자동차), 3) 원샷(One-shot) - 랜덤 이벤트(나뭇잎 소리, 문 삐걱).
핵심 요약
- Physical Surface 라인 트레이스로 재질별 발소리를 자동 선택한다
- 무기 사운드는 발사, 메카니즘, 탄피, 탄착, 꼬리음 레이어로 분리하여 구현한다
- 대사 시스템은 큐 관리, 더킹, 자막 연동을 포함해야 한다
- 환경 앰비언스는 베드, 디테일, 원샷 3계층 레이어링으로 풍부하게 만든다
도전 과제
배운 내용을 직접 실습해보세요
OnComponentHit 이벤트에서 Hit Result의 Impact Normal Velocity를 기반으로 충돌 세기를 계산하고, 세기에 비례하는 볼륨으로 사운드를 재생하세요. Physical Material별로 다른 사운드를 재생하는 시스템을 구현하세요.
캐릭터 Animation Notify에서 Line Trace로 바닥 Material을 감지하고, Material별(잔디, 돌, 나무, 금속) 발자국 Sound Cue를 재생하세요. 걷기/달리기 속도에 따라 볼륨과 간격을 조절하세요.
무기 사운드(발사, 재장전, 빈 탄창), 환경 사운드(바람, 비, 새소리), 캐릭터 사운드(발자국, 피격, 사망)를 통합 관리하는 게임플레이 오디오 매니저를 구현하세요. 거리 기반 LOD와 Concurrency 관리를 포함하세요.