This is old but… what i did was to handled the local smotheness of the Camera container with a FTimeline.
When a press crouch im call the native character crouch and then run the timeline ONLY on local player and with a simple compensation system got the smoothness for the FPS Local camera (im not using Spring arms to keep inmediatly response on inputs)
*Setup required values
StandingCapsuleHeight = Character->GetCapsuleComponent()->GetScaledCapsuleHalfHeight();
CrouchingCapsuleHeight = StandingCapsuleHeight * CrouchHeightScale;
- Get the relative camera location
FVector USlideCrouchComponent::GetRelativeCameraLocationOnCrouch(const float& Alpha) const
{
float CameraRelativeLocationZ;
const float DiffZPosition = StandingCapsuleHeight - CrouchingCapsuleHeight;
if (Character->GetGroundMovement() == EGroundMovement::Standing)
{
// On Uncrouching
CameraRelativeLocationZ = FMath::Lerp(
CameraRelativeLocation.Z, // to this
CameraRelativeLocation.Z - DiffZPosition, // from this
Alpha
);
}
else
{
// On Crouching or slide
CameraRelativeLocationZ = FMath::Lerp(
CameraRelativeLocation.Z + DiffZPosition, // from this
CameraRelativeLocation.Z, // to this
Alpha
);
}
return FVector(CameraRelativeLocation.X, CameraRelativeLocation.Y, CameraRelativeLocationZ);
}
*Method FTimeline execute on play or reverse
void USlideCrouchComponent::HandleCrouchHeight(const float Alpha) const
{
if (IsValid(Character) && IsValid(Character->GetFPSCamera()) && Character->GetLocalRole() == ROLE_AutonomousProxy)
{
Character->GetFPSCamera()->SetRelativeLocation(GetRelativeCameraLocationOnCrouch(Alpha));
}
}
- When press crouch:
character->Crouch();
CrouchTimeline.Play();
- When uncrouch
character->Uncrouch();
CrouchTimeline.Reverse();