Skip to content

Commit

Permalink
Fix an issue with character pose when stopping at low fps
Browse files Browse the repository at this point in the history
  • Loading branch information
Sixze committed Nov 23, 2024
1 parent 54f2593 commit 43b5caf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
53 changes: 25 additions & 28 deletions Source/ALS/Private/AlsAnimationInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ void UAlsAnimationInstance::RefreshVelocityBlend()
(FMath::Abs(RelativeVelocityDirection.X) + FMath::Abs(RelativeVelocityDirection.Y) + FMath::Abs(RelativeVelocityDirection.Z));
}

if (VelocityBlend.bInitializationRequired)
if (VelocityBlend.bInitializationRequired || Settings->Grounded.VelocityBlendInterpolationSpeed <= 0.0f)
{
VelocityBlend.bInitializationRequired = false;

Expand All @@ -761,44 +761,44 @@ void UAlsAnimationInstance::RefreshVelocityBlend()
}
else
{
const auto DeltaTime{GetDeltaSeconds()};
// WWe use UAlsMath::ExponentialDecay() instead of FMath::FInterpTo(), because FMath::FInterpTo() is very sensitive to large
// delta time, at low FPS interpolation becomes almost instant which causes issues with character pose during the stop.

VelocityBlend.ForwardAmount = FMath::FInterpTo(VelocityBlend.ForwardAmount,
UAlsMath::Clamp01(TargetVelocityBlend.X),
DeltaTime, Settings->Grounded.VelocityBlendInterpolationSpeed);
const auto InterpolationAmount{UAlsMath::ExponentialDecay(GetDeltaSeconds(), Settings->Grounded.VelocityBlendInterpolationSpeed)};

VelocityBlend.BackwardAmount = FMath::FInterpTo(VelocityBlend.BackwardAmount,
FMath::Abs(FMath::Clamp(TargetVelocityBlend.X, -1.0f, 0.0f)),
DeltaTime, Settings->Grounded.VelocityBlendInterpolationSpeed);
VelocityBlend.ForwardAmount = FMath::Lerp(VelocityBlend.ForwardAmount,
UAlsMath::Clamp01(TargetVelocityBlend.X),
InterpolationAmount);

VelocityBlend.LeftAmount = FMath::FInterpTo(VelocityBlend.LeftAmount,
FMath::Abs(FMath::Clamp(TargetVelocityBlend.Y, -1.0f, 0.0f)),
DeltaTime, Settings->Grounded.VelocityBlendInterpolationSpeed);
VelocityBlend.BackwardAmount = FMath::Lerp(VelocityBlend.BackwardAmount,
FMath::Abs(FMath::Clamp(TargetVelocityBlend.X, -1.0f, 0.0f)),
InterpolationAmount);

VelocityBlend.RightAmount = FMath::FInterpTo(VelocityBlend.RightAmount,
UAlsMath::Clamp01(TargetVelocityBlend.Y),
DeltaTime, Settings->Grounded.VelocityBlendInterpolationSpeed);
VelocityBlend.LeftAmount = FMath::Lerp(VelocityBlend.LeftAmount,
FMath::Abs(FMath::Clamp(TargetVelocityBlend.Y, -1.0f, 0.0f)),
InterpolationAmount);

VelocityBlend.RightAmount = FMath::Lerp(VelocityBlend.RightAmount,
UAlsMath::Clamp01(TargetVelocityBlend.Y),
InterpolationAmount);
}
}

void UAlsAnimationInstance::RefreshGroundedLean()
{
const auto TargetLeanAmount{GetRelativeAccelerationAmount()};

if (bPendingUpdate)
if (bPendingUpdate || Settings->General.LeanInterpolationSpeed <= 0.0f)
{
LeanState.RightAmount = TargetLeanAmount.Y;
LeanState.ForwardAmount = TargetLeanAmount.X;
}
else
{
const auto DeltaTime{GetDeltaSeconds()};

LeanState.RightAmount = FMath::FInterpTo(LeanState.RightAmount, TargetLeanAmount.Y,
DeltaTime, Settings->General.LeanInterpolationSpeed);
const auto InterpolationAmount{UAlsMath::ExponentialDecay(GetDeltaSeconds(), Settings->General.LeanInterpolationSpeed)};

LeanState.ForwardAmount = FMath::FInterpTo(LeanState.ForwardAmount, TargetLeanAmount.X,
DeltaTime, Settings->General.LeanInterpolationSpeed);
LeanState.RightAmount = FMath::Lerp(LeanState.RightAmount, TargetLeanAmount.Y, InterpolationAmount);
LeanState.ForwardAmount = FMath::Lerp(LeanState.ForwardAmount, TargetLeanAmount.X, InterpolationAmount);
}
}

Expand Down Expand Up @@ -1111,20 +1111,17 @@ void UAlsAnimationInstance::RefreshInAirLean()
GetRelativeVelocity() / ReferenceSpeed * Settings->InAir.LeanAmountCurve->GetFloatValue(InAirState.VerticalVelocity)
};

if (bPendingUpdate)
if (bPendingUpdate || Settings->General.LeanInterpolationSpeed <= 0.0f)
{
LeanState.RightAmount = TargetLeanAmount.Y;
LeanState.ForwardAmount = TargetLeanAmount.X;
}
else
{
const auto DeltaTime{GetDeltaSeconds()};

LeanState.RightAmount = FMath::FInterpTo(LeanState.RightAmount, TargetLeanAmount.Y,
DeltaTime, Settings->General.LeanInterpolationSpeed);
const auto InterpolationAmount{UAlsMath::ExponentialDecay(GetDeltaSeconds(), Settings->General.LeanInterpolationSpeed)};

LeanState.ForwardAmount = FMath::FInterpTo(LeanState.ForwardAmount, TargetLeanAmount.X,
DeltaTime, Settings->General.LeanInterpolationSpeed);
LeanState.RightAmount = FMath::Lerp(LeanState.RightAmount, TargetLeanAmount.Y, InterpolationAmount);
LeanState.ForwardAmount = FMath::Lerp(LeanState.ForwardAmount, TargetLeanAmount.X, InterpolationAmount);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct ALS_API FAlsRigUnit_ApplyFootOffsetRotation : public FRigUnitMutable
UPROPERTY(Meta = (Input, ClampMin = 0, ClampMax = 180, ForceUnits = "deg"))
float TwistLimitAngle{0.0f};

// The higher the value, the faster the interpolation. A zero value will result in instant interpolation.
// The higher the value, the faster the interpolation. A zero value results in instant interpolation.
UPROPERTY(Meta = (Input, ClampMin = 0))
float OffsetInterpolationSpeed{20.0f};

Expand Down
1 change: 1 addition & 0 deletions Source/ALS/Public/Settings/AlsGeneralAnimationSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct ALS_API FAlsGeneralAnimationSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ALS", Meta = (ClampMin = 0, ForceUnits = "cm/s"))
float MovingSmoothSpeedThreshold{150.0f};

// The higher the value, the faster the interpolation. A zero value results in instant interpolation.
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ALS", Meta = (ClampMin = 0))
float LeanInterpolationSpeed{4.0f};
};
1 change: 1 addition & 0 deletions Source/ALS/Public/Settings/AlsGroundedSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct ALS_API FAlsGroundedSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ALS")
TObjectPtr<UCurveFloat> RotationYawOffsetRightCurve;

// The higher the value, the faster the interpolation. A zero value results in instant interpolation.
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ALS", Meta = (ClampMin = 0))
float VelocityBlendInterpolationSpeed{12.0f};
};

0 comments on commit 43b5caf

Please sign in to comment.