먼저 사용할 사운드를 구해줍니다
프로젝트세팅의 Physics에 사용할 surface type을 지정해줍니다
피지컬 메테리얼을 생성해줍니다
해당 피지컬 메테리얼의 프로퍼티를 이름과 맞게 설정해줍니다
사운드를 적용할 바닥에 피지컬 메테리얼을 적용시킵니다
애니메이션 노티파이에서 캐릭터로부터 밑으로 라인트레이스를 쏴서 피지컬 메테리얼을 분간합니다
피지컬메테리얼을 c++에서 제어하기위한 build.cs모듈을 추가해줍니다
"PhysicsCore"
애님노티파이에서 호출할 플레이어바닥으로 라인트레이서를 쏴서
라인트레이서에 맞은 바닥의 피직스 머티리얼을 분간후
그에맞는 랜덤사운드를 호출하는 함수를 만들어줍니다
각각 맞는 사운드 동적배열을 추가해줍니다
UPROPERTY(EditAnywhere, Category = "Sound")
TArray<USoundBase*> sound_NormalTile;
UPROPERTY(EditAnywhere, Category = "Sound")
TArray<USoundBase*> sound_DungeonTile;
UPROPERTY(EditAnywhere, Category = "Sound")
TArray<USoundBase*> sound_Sand;
UPROPERTY(EditAnywhere, Category = "Sound")
TArray<USoundBase*> sound_Wood;
void ASwordCharacter::FootStep()
{
FVector startPoint = GetActorLocation();
FVector endPoint = startPoint - FVector(0.f, 0.f, 100.f);
FHitResult hit;
FCollisionQueryParams footStepParams;
footStepParams.AddIgnoredActor(this);
footStepParams.bTraceComplex = true;
bool bHitLineTraceFootStep = GetWorld()->LineTraceSingleByChannel(hit, startPoint, endPoint, ECC_Visibility, footStepParams);
if (bHitLineTraceFootStep)
{
EPhysicalSurface surfaceType = SurfaceType_Default;
UPhysicalMaterial* matFromMaterial = hit.PhysMaterial.Get();
if (matFromMaterial)
{
surfaceType = UPhysicalMaterial::DetermineSurfaceType(matFromMaterial);
}
else
{
if (hit.Component.IsValid())
{
UPhysicalMaterial* overridePhysMat = hit.Component->BodyInstance.GetSimplePhysicalMaterial();
if (overridePhysMat)
{
surfaceType = overridePhysMat->SurfaceType;
}
}
}
switch (surfaceType)
{
case SurfaceType_Default:
break;
//NormalTile
case SurfaceType1:
if (sound_NormalTile.Num() > 0)
{
int32 normalTileIndex = FMath::RandRange(0, sound_NormalTile.Num() - 1);
UGameplayStatics::PlaySoundAtLocation(GetWorld(), sound_NormalTile[normalTileIndex], hit.ImpactPoint);
}
break;
//DungeonTile
case SurfaceType2:
if (sound_DungeonTile.Num() > 0)
{
int32 dungeonTileIndex = FMath::RandRange(0, sound_DungeonTile.Num() - 1);
UGameplayStatics::PlaySoundAtLocation(GetWorld(), sound_DungeonTile[dungeonTileIndex], hit.ImpactPoint);
}
break;
//Sand
case SurfaceType3:
if (sound_Sand.Num() > 0)
{
int32 sandIndex = FMath::RandRange(0, sound_Sand.Num() - 1);
UGameplayStatics::PlaySoundAtLocation(GetWorld(), sound_Sand[sandIndex], hit.ImpactPoint);
}
break;
//Wood
case SurfaceType4:
if (sound_Wood.Num() > 0)
{
int32 woodIndex = FMath::RandRange(0, sound_Wood.Num() - 1);
UGameplayStatics::PlaySoundAtLocation(GetWorld(), sound_Wood[woodIndex], hit.ImpactPoint);
}
break;
default:
break;
}
}
}
해당 노티파이에서는 FootStep의 함수를 호출시킵니다
배열을 추가후 사운드를 추가해줍니다
'Unreal5 프로젝트 다이어리' 카테고리의 다른 글
Unreal - 일시정지 위젯 만들기 (0) | 2025.06.07 |
---|---|
Unreal - 위젯 나이아가라 (0) | 2025.06.06 |
Unreal - 위젯에 동영상 파일 추가하기 (인트로) (0) | 2025.05.30 |
Unreal - 새로하기, 이어하기 메인메뉴 만들기 (0) | 2025.05.29 |
Unreal - 던전 클리어 위젯 만들기 (0) | 2025.05.25 |