FVector startPos = 소환위치(FVector);
float maxRange = 10000.f;
// 카메라 기반으로 구하기
auto cameraManager = UGameplayStatics::GetPlayerCameraManager(GetWorld(), 0);
auto traceStartPos = UKismetMathLibrary::ProjectPointOnToPlane(cameraManager->GetCameraLocation(), startPos, cameraManager->GetActorForwardVector());
auto traceEndPos = traceStartPos + (cameraManager->GetActorForwardVector() * maxRange);
// 게임 뷰포트 가운데 지점 구하기
FVector2D vPortCenterPos = GEngine->GameViewport->Viewport->GetSizeXY() / 2.f;
FVector deprojPos, deprojDir;
UGameplayStatics::DeprojectScreenToWorld(UGameplayStatics::GetPlayerController(GetWorld(), 0), vPortCenterPos, deprojPos, deprojDir);
FVector rayStartPos = cameraManager->GetCameraLocation();
FVector rayEndPos = deprojPos + (deprojDir * maxRange);
FHitResult hitResult;
auto bTraced = GetWorld()->LineTraceSingleByChannel(hitResult, rayStartPos, rayEndPos, ECollisionChannel::ECC_Visibility);
FVector endPos = UKismetMathLibrary::SelectVector(hitResult.ImpactPoint, hitResult.TraceEnd, bTraced);
DrawDebugLine(GetWorld(), startPos, endPos, FColor::Red, true);
'게임엔진 > Unreal' 카테고리의 다른 글
[Unreal] 자료구조 순회 방법 (0) | 2022.08.04 |
---|---|
[Unreal] FTimerManager 타이머 설정 (0) | 2022.08.02 |
[Unreal] 문자열 변환 - FName, FText, FString (0) | 2022.07.31 |
[Unreal] FVector과 FRotator간 변환 (0) | 2022.07.31 |
[Unreal] C++ 버전 변경(C++ 20기능 사용) 방법과 모듈 (1) | 2022.07.24 |