AFPSCharacter::AFPSCharacter(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
// Create a CameraComponent
FirstPersonCameraComponent = ObjectInitializer.CreateDefaultSubobject(this, TEXT(“FirstPersonCamera”));
FirstPersonCameraComponent->SetupAttachment(GetCapsuleComponent());
// Position the camera a bit above the eyes
FirstPersonCameraComponent->RelativeLocation = FVector(0, 0, 40.0f + BaseEyeHeight);
// Allow the pawn to control rotation.
FirstPersonCameraComponent->bUsePawnControlRotation = true;
// Create a mesh component that will be used when being viewed from a '1st person' view (when controlling this pawn)
FirstPersonMesh = ObjectInitializer.CreateDefaultSubobject<USkeletalMeshComponent>(this, TEXT("FirstPersonMesh"));
FirstPersonMesh->SetOnlyOwnerSee(true); // only the owning player will see this mesh
FirstPersonMesh->SetupAttachment(FirstPersonCameraComponent);
FirstPersonMesh->bCastDynamicShadow = false;
FirstPersonMesh->CastShadow = false;
// everyone but the owner can see the regular body mesh
GetMesh()->SetOwnerNoSee(true);
}
img: