[UE5] TIL - 31 <DrawDebugCamera, GetPlayerViewPoint>

ChangJin·2024년 5월 12일
0

Unreal Engine5

목록 보기
59/102
post-thumbnail

2024-05-12

깃허브!
https://github.com/ChangJin-Lee/ARproject
https://github.com/ChangJin-Lee/SimpleShooter

느낀점
DrawDebugCamera로 RayCast를 하기 위한 baseLocation을 뷰포트에서 어떻게 나타낼지에 대해서 탐구했다. 3인칭 슈팅게임에서는 총에서 raycast를 쏘는 것이 아닌 카메라에서 raycast를 쏘는 것이 일반적인데, GetPlayerViewPoint를 사용해서 카메라의 Location과 Rotator를 가져올 수 있었다.

TIL

  • DrawDebugCamera
  • GetPlayerViewPoint

DrawDebugCamera

https://docs.unrealengine.com/4.27/en-US/API/Runtime/Engine/DrawDebugCamera/

  • 5.3 버전에 해당 함수에 대한 설명이 없어서 4.27 버전의 공식문서를 가져왔습니다.

  • Draw a debug camera shape. FOV is full angle in degrees.
  • 카메라 모양의 debug를 뷰포트에 그립니다.


  • Syntax는 다음과 같습니다.
  • UWorld, Location, Rotation, FOV, Scale, Color, bPersistent 정도가 디폴트로 쓰입니다.

void DrawDebugCamera
(
    const UWorld * InWorld,
    FVector const & Location,
    FRotator const & Rotation,
    float FOVDeg,
    float Scale,
    FColor const & Color,
    bool bPersistentLines,
    float LifeTime,
    uint8 DepthPriority
)

  • 다음처럼 총을 발사할 때 뷰포트에서 카메라의 위치를 가져온 후 해당 위치에 debug를 그려볼 수 있습니다.
void AGun::PullTrigger()
{
	UGameplayStatics::SpawnEmitterAttached(MuzzleFlash, Mesh, TEXT("MuzzleFlashSocket"));

	APawn* OwnerPawn = Cast<APawn>(GetOwner());

	if(OwnerPawn == nullptr) return;
	AController* OwnerController =  OwnerPawn->GetController();
	if(OwnerController == nullptr) return;

	FVector Location;
	FRotator Rotation;
	OwnerController->GetPlayerViewPoint(Location,Rotation);
	
	DrawDebugCamera(GetWorld(),  Location, Rotation, 90, 2, FColor::Red, true);

	// DrawDebugCamera(GetWorld(), GetActorLocation(), GetActorRotation(), 90, 2, FColor::Red, true);
	UE_LOG(LogTemp, Warning, TEXT("You Pull the Trigger!"));
}



GetPlayerViewPoint

https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Engine/GameFramework/APlayerController/GetPlayerViewPoint?application_version=5.3


  • Returns Player's Point of View For the AI this means the Pawn's 'Eyes' ViewPoint For a Human player, this means the Camera's ViewPoint

  • 플레이어의 point of view를 가져옵니다. 3인칭 슈팅게임에서는 실제 총구에서 RayCast를 쏘아 총알이 맞았는지를 탐지하면 안됩니다. 카메라에서 Raycast를 쏘아야합니다. 즉 캐릭터에 부착된 카메라에서 RayCast를 쏘아야 합니다.

  • AI 들은 실제 눈을 통해 보지만 플레이어는 카메라를 통해 viewport를 봅니다.


  • Syntax는 다음과 같습니다. 매개변수로 넣어준 변수에 Location과 Rotatr의 값을 할당해줍니다.
UFUNCTION(BlueprintCallable, Category = Pawn)
	ENGINE_API virtual void GetPlayerViewPoint( FVector& Location, FRotator& Rotation ) const;
void AController::GetPlayerViewPoint( FVector& out_Location, FRotator& out_Rotation ) const
{
	GetActorEyesViewPoint( out_Location, out_Rotation);
}
void APawn::GetActorEyesViewPoint( FVector& out_Location, FRotator& out_Rotation ) const
{
	out_Location = GetPawnViewLocation();
	out_Rotation = GetViewRotation();
}

  • 이제 실제 RayCast를 쏘아 총의 피격 위치를 알아내면 됩니다.
profile
Unreal Engine 클라이언트 개발자

0개의 댓글