From e2f70680d4cb1cb07ebd6e89887ceadfc3e9313a Mon Sep 17 00:00:00 2001 From: NeonDmn Date: Mon, 2 Jun 2025 01:08:44 +0200 Subject: [PATCH] fix: Frame independent Lerp & CoverAim camera jumping --- Exo.sln.DotSettings.user | 2 ++ .../Private/Characters/ExoPlayerCharacter.cpp | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 Exo.sln.DotSettings.user diff --git a/Exo.sln.DotSettings.user b/Exo.sln.DotSettings.user new file mode 100644 index 0000000..9c0e729 --- /dev/null +++ b/Exo.sln.DotSettings.user @@ -0,0 +1,2 @@ + + ForceIncluded \ No newline at end of file diff --git a/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp b/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp index 6119681..e0cf75f 100644 --- a/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp +++ b/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp @@ -117,44 +117,48 @@ void AExoPlayerCharacter::CrouchingFinished() void AExoPlayerCharacter::UpdateCameraHeight(float DeltaTime) { - if (FMath::IsNearlyEqual(GetCurrentEyeHeight(), TargetEyeHeight, 0.01f)) - { - return; - } - - const float NewHeight = FMath::Lerp(GetCurrentEyeHeight(), TargetEyeHeight, DeltaTime*5); - const FVector CamRelXY = CameraComponent->GetRelativeLocation(); - EyeHeight = GetFootOffset() + NewHeight; - CameraComponent->SetRelativeLocation(FVector(CamRelXY.X, CamRelXY.Y,EyeHeight)); + //if (FMath::IsNearlyEqual(EyeHeight, TargetEyeHeight, 0.01f)) + //{ + //CameraComponent->SetRelativeLocation(FVector(0.f, 0.f,EyeHeight)); + //return; + //} + const float LerpDelta = 1.0 - exp(-5 * DeltaTime); + EyeHeight = FMath::Lerp(EyeHeight, TargetEyeHeight, LerpDelta); + //const FVector CamRelXY = CameraComponent->GetRelativeLocation(); + const float RelEyeHeight = GetFootOffset() + EyeHeight; + //CameraComponent->SetRelativeLocation(FVector(CamRelXY.X, CamRelXY.Y,EyeHeight)); + CameraComponent->SetRelativeLocation(FVector(0.f, 0.f,RelEyeHeight)); } void AExoPlayerCharacter::ApplyCameraOffsets(float DeltaTime) { bool HasChanged = false; + const float LerpDelta = 1.0 - exp(-5 * DeltaTime); if (!FVector::PointsAreNear(EyeLocationOffset, TargetEyeLocationOffset, 0.01f)) { // Smoothly offset view - EyeLocationOffset = FMath::Lerp(EyeLocationOffset, TargetEyeLocationOffset, 5*DeltaTime); + EyeLocationOffset = FMath::Lerp(EyeLocationOffset, TargetEyeLocationOffset, LerpDelta); HasChanged = true; } if (!FMath::IsNearlyEqual(EyeRoll, TargetEyeRoll, 0.01f)) { // Smoothly rotate view - EyeRoll = FMath::Lerp(EyeRoll, TargetEyeRoll, DeltaTime*5); + EyeRoll = FMath::Lerp(EyeRoll, TargetEyeRoll, LerpDelta); HasChanged = true; } if (!HasChanged) { // Do not calculate anything if nothing changed + CameraComponent->AddRelativeLocation(EyeLocationOffset); return; } // Update actual camera position - const FVector FinalOffset = FVector(EyeLocationOffset.X, EyeLocationOffset.Y, + const FVector FinalLocation = FVector(EyeLocationOffset.X, EyeLocationOffset.Y, EyeLocationOffset.Z + TargetEyeHeight + GetFootOffset()); - CameraComponent->SetRelativeLocation(FinalOffset); + CameraComponent->SetRelativeLocation(FinalLocation); // Update actual camera rotation (Roll) FRotator NewRotator = GetController()->GetControlRotation();