Skip to content

Commit

Permalink
Prevent Character to climb on object with high velocity (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
seb-exiin committed Dec 1, 2020
1 parent 8263750 commit 97ca23a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter

void SetMovementModel();

bool IsComponentVelocityValid(UPrimitiveComponent* PrimitiveComponent, float MaxVelocity);

/** Input */

void PlayerForwardMovementInput(float Value);
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 97ca23a

Please sign in to comment.