Implemented ledge grab

Signed-off-by: TjgL <lithmoneo@gmail.com>
This commit is contained in:
TjgL 2025-03-12 16:15:24 +01:00
parent 502f8c3ce1
commit 7023da9ce4
3 changed files with 50 additions and 2 deletions

BIN
Content/Legumix/Player/BP_Play.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -19,6 +19,8 @@ ALMPlayer::ALMPlayer(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer.SetDefaultSubobjectClass<ULMMovementComponent>(CharacterMovementComponentName)) : Super(ObjectInitializer.SetDefaultSubobjectClass<ULMMovementComponent>(CharacterMovementComponentName))
{ {
LegumixMovementComponent = Cast<ULMMovementComponent>(GetCharacterMovement()); LegumixMovementComponent = Cast<ULMMovementComponent>(GetCharacterMovement());
LedgeGrabOrigin = CreateDefaultSubobject<USceneComponent>("LedgeGrabOrigin");
LedgeGrabOrigin->SetupAttachment(RootComponent);
PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.bCanEverTick = true;
@ -45,6 +47,8 @@ void ALMPlayer::BeginPlay()
GetCamera()->SetFieldOfView(ULMUserSettings::GetLegumixUserSettings()->FieldOfView); GetCamera()->SetFieldOfView(ULMUserSettings::GetLegumixUserSettings()->FieldOfView);
HealthComponent->OnHealthChanged.AddDynamic(this, &ALMPlayer::SetDisplayDamageParameters); HealthComponent->OnHealthChanged.AddDynamic(this, &ALMPlayer::SetDisplayDamageParameters);
MovementModeChangedDelegate.AddUniqueDynamic(this, &ALMPlayer::MovementChanged);
} }
void ALMPlayer::Tick(float DeltaTime) void ALMPlayer::Tick(float DeltaTime)
@ -228,6 +232,34 @@ void ALMPlayer::SetPlayerViewOcclusionPercent()
NextPlayerViewOcclusionPercent = CumulatedDamagesOnCurrentHitPeriod / HealthAtTheCurrentHitPeriodBeginning; NextPlayerViewOcclusionPercent = CumulatedDamagesOnCurrentHitPeriod / HealthAtTheCurrentHitPeriodBeginning;
} }
void ALMPlayer::MovementChanged(ACharacter* Character, EMovementMode PrevMovementMode, uint8 PreviousCustomMode)
{
if (GetCharacterMovement()->MovementMode == MOVE_Falling)
{
GetWorldTimerManager().SetTimer(LedgeGrabCheckTimer, this, &ALMPlayer::DoLedgeGrabCheck, LedgeGrabPollTime, true);
}
else if (PrevMovementMode == MOVE_Falling)
{
GetWorldTimerManager().ClearTimer(LedgeGrabCheckTimer);
}
}
void ALMPlayer::DoLedgeGrabCheck()
{
FVector Origin = LedgeGrabOrigin->GetComponentLocation();
FVector Dir = LedgeGrabOrigin->GetUpVector() * FVector(0, 0, -LedgeGrabTraceLength);
FVector Ray = Origin + Dir;
FHitResult Hit;
const bool Results = UKismetSystemLibrary::LineTraceSingleByProfile(GetWorld(), Origin, Ray, TEXT("BlockAll"), false
, {}, EDrawDebugTrace::None, Hit, true, FLinearColor::Red, FLinearColor::Green, 0.2f);
if (Results)
{
FVector TeleportLocation = FVector(Hit.Location.X, Hit.Location.Y, Hit.Location.Z + GetCapsuleComponent()->GetScaledCapsuleHalfHeight());
SetActorLocation(TeleportLocation, false, nullptr, ETeleportType::ResetPhysics);
}
}
FCollisionQueryParams ALMPlayer::GetIgnoreCharacterParams() FCollisionQueryParams ALMPlayer::GetIgnoreCharacterParams()
{ {
FCollisionQueryParams Params; FCollisionQueryParams Params;

View File

@ -102,6 +102,12 @@ public:
UFUNCTION(BlueprintNativeEvent, BlueprintCallable) UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
void OnPause(bool Paused); void OnPause(bool Paused);
UFUNCTION()
void MovementChanged(ACharacter* Character, EMovementMode PrevMovementMode, uint8 PreviousCustomMode);
UFUNCTION(BlueprintCallable)
void DoLedgeGrabCheck();
FCollisionQueryParams GetIgnoreCharacterParams(); FCollisionQueryParams GetIgnoreCharacterParams();
public: public:
@ -129,6 +135,9 @@ private:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true)) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true))
TObjectPtr<ULMHealthComponent> HealthComponent; TObjectPtr<ULMHealthComponent> HealthComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix|LedgeGrab", meta = (AllowPrivateAccess = true))
TObjectPtr<USceneComponent> LedgeGrabOrigin;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Legumix, meta = (AllowPrivateAccess = true)) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Legumix, meta = (AllowPrivateAccess = true))
TObjectPtr<UMaterialInstanceDynamic> DamageDynamicMaterialInstance; TObjectPtr<UMaterialInstanceDynamic> DamageDynamicMaterialInstance;
@ -188,6 +197,12 @@ private:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true)) UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true))
ETeam Team = ETeam::ET_Player; ETeam Team = ETeam::ET_Player;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix|LedgeGrab", meta = (AllowPrivateAccess = true, ClampMin = 0.f))
float LedgeGrabPollTime = 0.2f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix|LedgeGrab", meta = (AllowPrivateAccess = true, ClampMin = 0.f))
float LedgeGrabTraceLength = 44.f;
/** /**
* Actualize all parameters needed to calculate PlayerViewOcclusionPercent * Actualize all parameters needed to calculate PlayerViewOcclusionPercent
*/ */
@ -209,4 +224,5 @@ private:
private: private:
FRandomStream SpreadStream; FRandomStream SpreadStream;
FTimerHandle LedgeGrabCheckTimer;
}; };