Hello, I am having an issue where the camera is rotating about the new location rather than the original location. Basically I am making a true FPS style camera location from the head socket and VInterpTo the new location of the “gun” (currently using a torus-like mesh as a placeholder). In the normal state it works fine, but when I zoom in, it starts to rotate from the new point instead of from the head.
Code:
void AShooterCameraManager::UpdateViewTarget(FTViewTarget& OutVT, float DeltaTime) {
Super::UpdateViewTarget(OutVT, DeltaTime);
ABasePlayerController* ShooterController = Cast<ABasePlayerController>(GetOwningPlayerController());
if (ShooterController != nullptr) {
AShooterCharacter* Character = Cast<AShooterCharacter>(ShooterController->GetViewTarget());
if (Character != nullptr && Character->GetAbilitySystemComponent()) {
// Standard Camera Management
float Pitch = GetOwningPlayerController()->GetControlRotation().Pitch;
if (Pitch > 90.f)
{
// map pitch from [270, 360) to [-90, 0)
FVector2D InRange(270.f, 360.f);
FVector2D OutRange(-90.f, 0.f);
Pitch = FMath::GetMappedRangeValueClamped(InRange, OutRange, Pitch);
}
float Yaw = GetOwningPlayerController()->GetControlRotation().Yaw;
FRotator ControlRot = FRotator(Pitch, Yaw, GetOwningPlayerController()->GetControlRotation().Roll);
//OutVT.POV.Rotation = ControlRot;
// Set default target location
TargetLocation = Character->GetMesh()->GetSocketLocation(FName("head"));
TargetRotation = ControlRot;
// ADS Camera Management
if (Character->GetAbilitySystemComponent()->GetTagCount(ShooterGameplayTags::Abilities_ADS) == 1) {
TargetLocation = Character->GetGunComponent()->GetSocketLocation(FName("Muzzle")) - FVector(20.0f, 10.0f, 0.f);
}
if (!bInterpolating) {
bInterpolating = true;
StartLocation = OutVT.POV.Location;
StartRotation = OutVT.POV.Rotation;
}
// Interpolate between StartLocation and TargetLocation
FVector NewLocation = FMath::VInterpTo(OutVT.POV.Location, TargetLocation, DeltaTime, InterpolationSpeed);
// Update camera location
OutVT.POV.Location = NewLocation;
// Interpolate between StartRotation and TargetRotation
FRotator NewRotation = FMath::RInterpTo(OutVT.POV.Rotation, TargetRotation, DeltaTime, InterpolationSpeed);
// Update camera rotation
OutVT.POV.Rotation = NewRotation;
// Check if interpolation is complete
if (NewLocation.Equals(TargetLocation, 1.0f)) {
bInterpolating = false;
}
This is the photo of the original state, which works
This is when I ADS and look left
This is when I ADS and look right
This is when I ADS and look up
Any ideas on how to fix it so that the aim offset stays the same as when the camera is in the head?