Hey guys,
I’ve been trying to separate the camera used in my game from the possessed pawn. I want to do this because the possessed pawn changes during gameplay, but I want to keep the same camera, to have a smooth transition between pawns.
For now, I have gotten the camera to focus on my pawn. To do this,
I added two lines to my constructor :
ATrollPlayerController::ATrollPlayerController(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
PrimaryActorTick.bCanEverTick = true;
bAutoManageActiveCameraTarget = false;
SetViewTarget(GetPawn());
}
And I also tried to override CalcCamera.
void ATrollPlayerController::CalcCamera(float DeltaTime, struct FMinimalViewInfo& OutResult)
{
FVector boom;
boom = FVector(-200, 0, 20);
OutResult.Location = GetPawn()->GetActorLocation() + boom;
/*if (bFindCameraComponentWhenViewTarget)
{
// Look for the first active camera component and use that for the view
TInlineComponentArray<UCameraComponent*> Cameras;
GetComponents<UCameraComponent>(Cameras);
for (UCameraComponent* CameraComponent : Cameras)
{
if (CameraComponent->bIsActive)
{
}
}
}*/
}
OutResult.Location = GetPawn()->GetActorLocation() + boom;
This line makes the camera follow the movements of the pawn. The boom FVector is a sort of makeshift spring arm so I can see my pawn from the outside and make sure it is changing properly.
The “if” is a bit of code that I was recommended to use in an answerhub thread, but I don’t really understand what it does. It seem to iterate through cameras and find the active one, but how do I use this?
My final goal would be to be able to control the pitch and yaw of this camera similarly to the third person template.