Unreal - Foot Step Sound

2025. 5. 30. 22:42·Unreal5 프로젝트 다이어리

먼저 사용할 사운드를 구해줍니다

 

프로젝트세팅의 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
'Unreal5 프로젝트 다이어리' 카테고리의 다른 글
  • Unreal - 일시정지 위젯 만들기
  • Unreal - 위젯 나이아가라
  • Unreal - 위젯에 동영상 파일 추가하기 (인트로)
  • Unreal - 새로하기, 이어하기 메인메뉴 만들기
lucodev
lucodev
커피와 노트북 그리고 개발
  • lucodev
    루코 개발테이블
    lucodev
  • 전체
    오늘
    어제
    • 분류 전체보기 (125) N
      • Unreal5 프로젝트 다이어리 (73)
      • Unreal5 프로젝트 다이어리2 (5) N
      • Unreal 팁 (8)
      • Unreal 디버깅 (8)
      • C++ 프로그래머스 다이어리 (23) N
        • Stack (3)
        • Hash (4)
        • Heap (2)
        • Sort (3) N
      • 코드 개인보관함 (8)
  • 인기 글

  • 최근 글

  • 최근 댓글

  • 링크

  • 공지사항

  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 태그

    언리얼 비헤이비어트리
    언리얼 페이드 아웃
    언리얼 로딩
    언리얼 motionmatching
    unreal loading
    unreal 로딩
    unreal look at
    언리얼 로딩창
    unreal 시퀀스
    unreal 컷씬
    언리얼 behavior tree
    언리얼
    언리얼 시퀀스
    언리얼 look at
    언리얼 컷씬
    언리얼 모션매칭
    언리얼 foot step
    언리얼 behaviortree
    unreal 모션매칭
    unreal sequence
  • hELLO· Designed By정상우.v4.10.3
lucodev
Unreal - Foot Step Sound
상단으로

티스토리툴바