13 - Camera
An APlayerCameraManager subclass that applies a shoulder offset and a target FOV with easing in UpdateCamera.
Full source
include "CoreMinimal.h"
include "GameFramework/PlayerCameraManager.h"
uclass AExampleCamera : APlayerCameraManager meta: api=EXAMPLES_API
{
prop public FVector ShoulderOffset EditAnywhere BlueprintReadWrite category="Camera" default=FVector(0.0f, 160.0f, -60.0f)
prop public float TargetFOV EditAnywhere BlueprintReadWrite category="Camera" default=80.0f
prop public float FOVBlendSpeed EditAnywhere BlueprintReadWrite category="Camera" default=5.0f
method public virtual void UpdateCamera(float DeltaTime) override {
Super::UpdateCamera(DeltaTime);
if (APlayerController* PC = GetOwningPlayerController())
{
FVector NewLoc = PC->PlayerCameraManager->GetCameraLocation(); // or use POV
NewLoc += ShoulderOffset;
PC->PlayerCameraManager->SetCameraLocation(NewLoc);
PC->PlayerCameraManager->SetFOV(FMath::FInterpTo(GetCameraFOV(), TargetFOV, DeltaTime, FOVBlendSpeed));
}
}
}
Line by line
uclass AExampleCamera : APlayerCameraManager- a camera manager (per-player camera controller).prop public FVector ShoulderOffset ... default=FVector(0, 160, -60)- an over-the-shoulder offset (classic third-person).prop public float TargetFOV ... default=80.0f- the aim FOV.prop public float FOVBlendSpeed ... default=5.0f- easing speed.UpdateCamera(float DeltaTime)- the per-frame camera update hook.FMath::FInterpTo(...)- frame-rate independent interpolation towardTargetFOVatFOVBlendSpeed.
Notes
UpdateCamera is the correct hook for camera-manager-level adjustments. For a per-USpringArm shoulder offset you'd instead set TargetOffset on the arm - this example shows the manager-level approach. FInterpTo gives smooth FOV transitions during aim-down-sights etc.
Next: 14 - Data Asset.