diff --git a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp index d6aef285..21ea9cef 100644 --- a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp +++ b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp @@ -564,6 +564,14 @@ void AALSBaseCharacter::SetMovementModel() MovementData = *OutRow; } +bool AALSBaseCharacter::IsComponentVelocityValid(UPrimitiveComponent* PrimitiveComponent, float MaxVelocity) +{ + FVector PrimitiveComponentVelocity = PrimitiveComponent->GetComponentVelocity(); + + return (PrimitiveComponentVelocity.Size() < MaxVelocity); +} + + void AALSBaseCharacter::SetHasMovementInput(bool bNewHasMovementInput) { bHasMovementInput = bNewHasMovementInput; @@ -1231,7 +1239,18 @@ bool AALSBaseCharacter::MantleCheck(const FALSMantleTraceSettings& TraceSettings // Not a valid surface to mantle return false; } + + if (HitResult.GetComponent() != nullptr) + { + UPrimitiveComponent* PrimitiveComponent = HitResult.GetComponent(); + if (!IsComponentVelocityValid(PrimitiveComponent, AcceptableVelocityWhileMantling)) + { + //The surface to mantle moves too fast + return false; + } + } + const FVector InitialTraceImpactPoint = HitResult.ImpactPoint; const FVector InitialTraceNormal = HitResult.ImpactNormal; @@ -1302,6 +1321,13 @@ void AALSBaseCharacter::MantleUpdate(float BlendIn) { // Step 1: Continually update the mantle target from the stored local transform to follow along with moving objects MantleTarget = UALSMathLibrary::MantleComponentLocalToWorld(MantleLedgeLS); + + if (MantleLedgeLS.Component != nullptr && !IsComponentVelocityValid(MantleLedgeLS.Component, AcceptableVelocityWhileMantling)) + { + //The surface to mantle moves too fast + MantleEnd(); + return; + } // Step 2: Update the Position and Correction Alphas using the Position/Correction curve set for each Mantle. const FVector CurveVec = MantleParams.PositionCorrectionCurve diff --git a/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h b/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h index f91bf605..be6e7964 100644 --- a/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h +++ b/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h @@ -405,6 +405,8 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter void SetMovementModel(); + bool IsComponentVelocityValid(UPrimitiveComponent* PrimitiveComponent, float MaxVelocity); + /** Input */ void PlayerForwardMovementInput(float Value); @@ -528,6 +530,9 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Mantle System") UCurveFloat* MantleTimelineCurve; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Mantle System") + float AcceptableVelocityWhileMantling = 10.0f; + /** Components */ UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Components")