fix: Frame independent Lerp & CoverAim camera jumping

This commit is contained in:
NeonDmn 2025-06-02 01:08:44 +02:00
parent 366ee209c7
commit e2f70680d4
2 changed files with 19 additions and 13 deletions

2
Exo.sln.DotSettings.user Normal file
View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=570E1760_002D6802_002D3FBC_002D9C08_002D3D91E8C32562_002Fdl_003ASource_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FUnreal_003FUE_005F5_002E3_003FEngine_003FSource_002Fd_003ARuntime_002Fd_003AEngine_002Fd_003APrivate_002Ff_003ACharacter_002Ecpp/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>

View File

@ -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();