오늘의 목표

 

언리얼 스타터 강의 2개 복습

언리얼 마스터 과제 (샷건 만들기) 진행

 


 

언리얼 마스터 3번 과제

 

멀티 라인 트레이스로 샷건 만들기

 

void ABasicShotgun::StartMultiTrace()
{

	TArray<FHitResult> HitResult;
	TArray<AActor*> ActorsToIgnore;
	ActorsToIgnore.Add(this);

	for (int i = 0; i < 9; ++i) 
	{
		float RandomYaw = FMath::FRandRange(-SpreadRadius, SpreadRadius);
		float RandomPitch = FMath::FRandRange(-SpreadRadius, SpreadRadius);

		FRandomStream RandomStream;
		RandomStream.GenerateNewSeed();
		FVector ShootDirection = RandomStream.VRandCone(GetActorForwardVector(), FMath::DegreesToRadians(SpreadRadius));

		FVector StartPos = GetActorLocation();
		FVector EndPos = StartPos + ShootDirection * 1000.f;

		bool bHit = UKismetSystemLibrary::LineTraceMulti(
			GetWorld(),
			StartPos,
			EndPos,
			UEngineTypes::ConvertToTraceType(ECC_Visibility),
			false,
			ActorsToIgnore, 
			EDrawDebugTrace::ForDuration,
			HitResult,
			true,
			FLinearColor::Red,
			FLinearColor::Green
		);
	}

 

랜덤 원뿔형 모양으로 랜덤 위치를 잡아주는 RandomStream.VRandCone 함수를 사용하고, 해당 사격 구현부를 for loop으로 묶음으로서 여러 발을 한 번에 동시에 발사하도록 구현함.

'Unreal5 공부 > TIL' 카테고리의 다른 글

2026/06/04 TIL  (0) 2026.06.05
2026/06/02 TIL  (0) 2026.06.02
2026/05/29 TIL  (0) 2026.05.29
2026/05/28 TIL  (0) 2026.05.28
2026/05/27 TIL  (0) 2026.05.27

+ Recent posts