It took me a while to finally get to a point where I have my default pawn, and it has a camera component at the correct relative location to start and facing the right way.
In the game I am trying to create, however, I want the camera to be fixed, so it doesn’t move with the player as the player flaps up and down.
Based on the CameraDirector tutorial, I had thought I could instantiate a separate Camera actor in the room and have a pointer to that during my build, later using SetViewTarget(). However, when I try that approach, Unreal Engine crashes, and I have to recompile my old code before I can even open the project again.
I assume there must be a better way. Here is the *.cpp code I have at present, with the camera that moves up and down with the player. Remember, I want a FIXED camera, not a mobile one.
//Create a third person camera component
ThirdPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("ThirdPersonCamera"));
check(ThirdPersonCameraComponent != nullptr);
//Position the camera about 5 meters away from the bird, sideways
ThirdPersonCameraComponent->SetRelativeLocation(FVector(CAMERA_OFFSET_X, CAMERA_OFFSET_Y, CAMERA_OFFSET_Z));
//Rotate the camera to face the player, and so that player appears to face to the right.
ThirdPersonCameraComponent->SetRelativeRotation(FRotator(CAMERA_ROTATE_X, CAMERA_ROTATE_Y, CAMERA_ROTATE_Z));
//Create a first-person mesh component for the owning player.
PlayerMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("PlayerMesh"));
check(PlayerMesh != nullptr);
//Assign the mesh as the root component of the player object
RootComponent = PlayerMesh;
//Then attach the camera as an attachment
ThirdPersonCameraComponent->SetupAttachment(PlayerMesh);