언리얼엔진5/각종 지식

[UE5] FPS 에임 오프셋 만들기 (캐릭터 상체 상하 움직임)

Rocketbabydolls 2024. 6. 1. 12:51

 

레퍼런스

 

https://youtu.be/jHM7JzsNyvQ

 

 

   원리는 간단하다. aim offset 1D를 통해  마네킹의 spine_02 를 -90부터 90까지 변환시켜준다. 

단지 헤멧던 원리의 부분은 후반의 블루프린트 부분이었는데, base aim rotation(컨트롤러가 바라보는 방향의 rotation 값) 을 가져와서 pitch 가  180 이상이면 그대로 적용하고, 180 이하이면 -360 값을 해 주는 부분이었다.

 

헤멧던 원리 부분

 

 

FRotator APawn::GetBaseAimRotation() const
{
   // If we have a controller, by default we aim at the player's 'eyes' direction
   // that is by default Controller.Rotation for AI, and camera (crosshair) rotation for human players.
   FVector POVLoc;
   FRotator POVRot;
   if( Controller != nullptr && !InFreeCam() )
   {
      Controller->GetPlayerViewPoint(POVLoc, POVRot);
      return POVRot;
   }

   // If we have no controller, we simply use our rotation
   POVRot = GetActorRotation();

   // If our Pitch is 0, then use a replicated view pitch
   if( FMath::IsNearlyZero(POVRot.Pitch) )
   {
      if (BlendedReplayViewPitch != 0.0f)
      {
         // If we are in a replay and have a blended value for playback, use that
         POVRot.Pitch = BlendedReplayViewPitch;
      }
      else
      {
         // Else use the RemoteViewPitch
         const UWorld* World = GetWorld();
         const UDemoNetDriver* DemoNetDriver = World ? World->GetDemoNetDriver() : nullptr;

         if (DemoNetDriver && DemoNetDriver->IsPlaying() && (DemoNetDriver->GetPlaybackEngineNetworkProtocolVersion() < FEngineNetworkCustomVersion::PawnRemoteViewPitch))
         {
            POVRot.Pitch = RemoteViewPitch;
            POVRot.Pitch = POVRot.Pitch * 360.0f / 255.0f;
         }
         else
         {
            POVRot.Pitch = FRotator::DecompressAxisFromByte(RemoteViewPitch);
         }
      }
   }

   return POVRot;
}

 

   A(Listen Server), B(Client) 가 있다고 하자. 그러면 당연하게도 로컬에서 A의 Pitch의 범위는 -90에서 90 이 나오게 된다.  -10과 350은 똑같고, A는 B의 Pitch를 0~360의 압축된 8bit 값으로 받게 된다. 그리고 컨트롤러는 -90~90 피치까지밖에 볼 수 없으니..  180이상의 값이 나올 때만 -360을 해 주면 설정한 Aim offset과 맞는 애니메이션으로 연결함과 동시에 리플리케이션으로도 잘 보이게 된다.

 

 

수기로 정리해 보았다.