diff --git a/Source/ALSCamera/Private/AlsCameraComponent.cpp b/Source/ALSCamera/Private/AlsCameraComponent.cpp index 5f0f88fd5..c85f37c6d 100644 --- a/Source/ALSCamera/Private/AlsCameraComponent.cpp +++ b/Source/ALSCamera/Private/AlsCameraComponent.cpp @@ -341,34 +341,7 @@ FRotator UAlsCameraComponent::CalculateCameraRotation(const FRotator& CameraTarg const auto RotationLag{GetAnimInstance()->GetCurveValue(UAlsCameraConstants::RotationLagCurveName())}; - if (!Settings->bEnableCameraLagSubstepping || - DeltaTime <= Settings->CameraLagSubstepping.LagSubstepDeltaTime || - RotationLag <= 0.0f) - { - return UAlsRotation::ExponentialDecayRotation(CameraRotation, CameraTargetRotation, DeltaTime, RotationLag); - } - - const auto CameraInitialRotation{CameraRotation}; - const auto SubstepRotationSpeed{(CameraTargetRotation - CameraInitialRotation).GetNormalized() * (1.0f / DeltaTime)}; - - auto NewCameraRotation{CameraRotation}; - auto PreviousSubstepTime{0.0f}; - - for (auto SubstepNumber{1};; SubstepNumber++) - { - const auto SubstepTime{SubstepNumber * Settings->CameraLagSubstepping.LagSubstepDeltaTime}; - if (SubstepTime < DeltaTime - UE_SMALL_NUMBER) - { - NewCameraRotation = FMath::RInterpTo(NewCameraRotation, CameraInitialRotation + SubstepRotationSpeed * SubstepTime, - SubstepTime - PreviousSubstepTime, RotationLag); - - PreviousSubstepTime = SubstepTime; - } - else - { - return FMath::RInterpTo(NewCameraRotation, CameraTargetRotation, DeltaTime - PreviousSubstepTime, RotationLag); - } - } + return UAlsRotation::ExponentialDecayRotation(CameraRotation, CameraTargetRotation, DeltaTime, RotationLag); } FVector UAlsCameraComponent::CalculatePivotLagLocation(const FQuat& CameraYawRotation, const float DeltaTime, const bool bAllowLag) const @@ -385,53 +358,11 @@ FVector UAlsCameraComponent::CalculatePivotLagLocation(const FQuat& CameraYawRot const auto LocationLagY{GetAnimInstance()->GetCurveValue(UAlsCameraConstants::LocationLagYCurveName())}; const auto LocationLagZ{GetAnimInstance()->GetCurveValue(UAlsCameraConstants::LocationLagZCurveName())}; - if (!Settings->bEnableCameraLagSubstepping || - DeltaTime <= Settings->CameraLagSubstepping.LagSubstepDeltaTime || - (LocationLagX <= 0.0f && LocationLagY <= 0.0f && LocationLagZ <= 0.0f)) - { - return CameraYawRotation.RotateVector({ - UAlsMath::ExponentialDecay(RelativePivotInitialLagLocation.X, RelativePivotTargetLocation.X, DeltaTime, LocationLagX), - UAlsMath::ExponentialDecay(RelativePivotInitialLagLocation.Y, RelativePivotTargetLocation.Y, DeltaTime, LocationLagY), - UAlsMath::ExponentialDecay(RelativePivotInitialLagLocation.Z, RelativePivotTargetLocation.Z, DeltaTime, LocationLagZ) - }); - } - - const auto SubstepMovementSpeed{(RelativePivotTargetLocation - RelativePivotInitialLagLocation) / DeltaTime}; - - auto RelativePivotLagLocation{RelativePivotInitialLagLocation}; - auto PreviousSubstepTime{0.0f}; - - for (auto SubstepNumber{1};; SubstepNumber++) - { - const auto SubstepTime{SubstepNumber * Settings->CameraLagSubstepping.LagSubstepDeltaTime}; - if (SubstepTime < DeltaTime - UE_SMALL_NUMBER) - { - const auto SubstepRelativePivotTargetLocation{RelativePivotInitialLagLocation + SubstepMovementSpeed * SubstepTime}; - const auto SubstepDeltaTime{SubstepTime - PreviousSubstepTime}; - - RelativePivotLagLocation.X = FMath::FInterpTo(RelativePivotLagLocation.X, SubstepRelativePivotTargetLocation.X, - SubstepDeltaTime, LocationLagX); - RelativePivotLagLocation.Y = FMath::FInterpTo(RelativePivotLagLocation.Y, SubstepRelativePivotTargetLocation.Y, - SubstepDeltaTime, LocationLagY); - RelativePivotLagLocation.Z = FMath::FInterpTo(RelativePivotLagLocation.Z, SubstepRelativePivotTargetLocation.Z, - SubstepDeltaTime, LocationLagZ); - - PreviousSubstepTime = SubstepTime; - } - else - { - const auto RemainingDeltaTime{DeltaTime - PreviousSubstepTime}; - - RelativePivotLagLocation.X = FMath::FInterpTo(RelativePivotLagLocation.X, RelativePivotTargetLocation.X, - RemainingDeltaTime, LocationLagX); - RelativePivotLagLocation.Y = FMath::FInterpTo(RelativePivotLagLocation.Y, RelativePivotTargetLocation.Y, - RemainingDeltaTime, LocationLagY); - RelativePivotLagLocation.Z = FMath::FInterpTo(RelativePivotLagLocation.Z, RelativePivotTargetLocation.Z, - RemainingDeltaTime, LocationLagZ); - - return CameraYawRotation.RotateVector(RelativePivotLagLocation); - } - } + return CameraYawRotation.RotateVector({ + UAlsMath::ExponentialDecay(RelativePivotInitialLagLocation.X, RelativePivotTargetLocation.X, DeltaTime, LocationLagX), + UAlsMath::ExponentialDecay(RelativePivotInitialLagLocation.Y, RelativePivotTargetLocation.Y, DeltaTime, LocationLagY), + UAlsMath::ExponentialDecay(RelativePivotInitialLagLocation.Z, RelativePivotTargetLocation.Z, DeltaTime, LocationLagZ) + }); } FVector UAlsCameraComponent::CalculatePivotOffset() const diff --git a/Source/ALSCamera/Public/AlsCameraSettings.h b/Source/ALSCamera/Public/AlsCameraSettings.h index b2bb173eb..fa9615961 100644 --- a/Source/ALSCamera/Public/AlsCameraSettings.h +++ b/Source/ALSCamera/Public/AlsCameraSettings.h @@ -63,15 +63,6 @@ struct ALSCAMERA_API FAlsThirdPersonCameraSettings FAlsTraceDistanceSmoothingSettings TraceDistanceSmoothing; }; -USTRUCT(BlueprintType) -struct ALSCAMERA_API FAlsCameraLagSubsteppingSettings -{ - GENERATED_BODY() - - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ALS", Meta = (ClampMin = 0.005, ClampMax = 0.5, ForceUnits = "s")) - float LagSubstepDeltaTime{1.0f / 60.0f}; -}; - UCLASS(Blueprintable, BlueprintType) class ALSCAMERA_API UAlsCameraSettings : public UDataAsset { @@ -92,13 +83,6 @@ class ALSCAMERA_API UAlsCameraSettings : public UDataAsset UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings") FAlsThirdPersonCameraSettings ThirdPerson; - UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings", Meta = (InlineEditConditionToggle)) - uint8 bEnableCameraLagSubstepping : 1 {false}; - - UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings", - DisplayName = "Enable Camera Lag Substepping", Meta = (EditCondition = "bEnableCameraLagSubstepping")) - FAlsCameraLagSubsteppingSettings CameraLagSubstepping; - UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings") FPostProcessSettings PostProcess;