Search code examples
c++camerarotationmultiplayerunreal-engine4

UE4 - Spectator does not rotate(pitch) when using CameraComponent


my spectator does not receive any pitch rotation from the followed player.


I am trying to work with ShooterGame project to make a proof of concept FPS spectator feature. I've added code in GameMode which switches VictimPlayer to a spectator mode:

VictimPlayerState->bIsSpectator = true;
PlayerController->ChangeState(NAME_Spectating);
PlayerController->ClientGotoState(NAME_Spectating);

I've also added logic to a PlayerController which switches the spectator's view to the next player:

void AShooterPlayerController::BeginSpectatingState()
{
    Super::BeginSpectatingState();

    ServerViewNextPlayer();
}

And it's working perfetly fine. But if I add CameraComponent to the ShooterCharacter - my spectator does not recieve any pitch rotation.

AShooterCharacter::AShooterCharacter(const FObjectInitializer& ObjectInitializer)
    : Super(ObjectInitializer.SetDefaultSubobjectClass<UShooterCharacterMovement>(ACharacter::CharacterMovementComponentName))
{

    FirstPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera"));
    FirstPersonCameraComponent->SetupAttachment(GetCapsuleComponent());
    FirstPersonCameraComponent->RelativeLocation = FVector(-39.56f, 1.75f, 64.f); // Position the camera
    FirstPersonCameraComponent->bUsePawnControlRotation = true;

    Mesh1P = ObjectInitializer.CreateDefaultSubobject<USkeletalMeshComponent>(this, TEXT("PawnMesh1P"));
    Mesh1P->SetupAttachment(FirstPersonCameraComponent);
    GetMesh()->SetupAttachment(FirstPersonCameraComponent);
...

What am I missing here? I believe CameraComponent is a standard way to change the default's camera position, so spectator mechanism should support this. I will be grateful for any help.


Solution

  • Turns out that "Use Controller Rotation Pitch" has to be set to true(Yaw is true by default) on Pawn. Issue solved.