Download

How to setup pitch/yaw control on the player controller's camera.

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.

Bump of sorts? Is this allowed? It’s just that I’m quite helpless here, I’d be happy with just a starting point from which to start working.

Probably your best approach is to do something like



YourController::CalcCamera()
{
  if(!GetPawn()) //No Pawn
{
 OutResult.Location = GetActorLocation(); //Sets our location/rotation to ourself
 OutResult.Rotation = GetActorRotation();
}
else //We have a pawn
{
  OutResult.Location = GetPawn()->GetActorLocation() + boom;
  OutResult.Rotation = GetPawn()->GetActorRotation() + boomrotation;
}
}

then in your unpossess function



YourController::UnPossess()
{
  SetActorLocation = GetPawn()->GetActorLocation() + boom;
  SetActorRotation = GetPawn()->GetActorRotatino() + boomrotation;  
  
  Super:UnPossess();
}

edit: or you could also just mimick the Pawn’s setup. And create your own CameraComponent on the actual controller, and then you’re just modifying that the whole time, rather than the pawn’s.