From c913a7c00bf2981d5a1352aa3b8a5ae4bc518944 Mon Sep 17 00:00:00 2001 From: TjgL Date: Fri, 28 Mar 2025 18:04:58 +0100 Subject: [PATCH] Implemented coyote time Signed-off-by: TjgL --- Source/LegumeMix/Private/Player/LMPlayer.cpp | 18 +++++++++++++++++- Source/LegumeMix/Public/Player/LMPlayer.h | 9 +++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Source/LegumeMix/Private/Player/LMPlayer.cpp b/Source/LegumeMix/Private/Player/LMPlayer.cpp index f5b5f86..d52007e 100644 --- a/Source/LegumeMix/Private/Player/LMPlayer.cpp +++ b/Source/LegumeMix/Private/Player/LMPlayer.cpp @@ -113,7 +113,13 @@ int ALMPlayer::RemoveAmmo(const EAmmoType AmmoType, const int Count) const bool ALMPlayer::CanJumpInternal_Implementation() const { - return JumpIsAllowedInternal(); + return JumpIsAllowedInternal() || bIsInCoyoteTime; +} + +void ALMPlayer::OnJumped_Implementation() +{ + Super::OnJumped_Implementation(); + bIsInCoyoteTime = false; } void ALMPlayer::AddAmmo(const EAmmoType Ammo, const int AmmoCount) @@ -245,6 +251,16 @@ void ALMPlayer::SetPlayerViewOcclusionPercent() NextPlayerViewOcclusionPercent = CumulatedDamagesOnCurrentHitPeriod / HealthAtTheCurrentHitPeriodBeginning; } +void ALMPlayer::OnWalkingOffLedge_Implementation(const FVector& PreviousFloorImpactNormal, + const FVector& PreviousFloorContactNormal, const FVector& PreviousLocation, float TimeDelta) +{ + Super::OnWalkingOffLedge_Implementation(PreviousFloorImpactNormal, PreviousFloorContactNormal, PreviousLocation, + TimeDelta); + + bIsInCoyoteTime = true; + GetWorldTimerManager().SetTimer(CoyoteCheckTimer, this, &ALMPlayer::FinishCoyoteTime, CoyoteTimeLength, false); +} + void ALMPlayer::MovementChanged(ACharacter* Character, EMovementMode PrevMovementMode, uint8 PreviousCustomMode) { if (GetCharacterMovement()->MovementMode == MOVE_Falling) diff --git a/Source/LegumeMix/Public/Player/LMPlayer.h b/Source/LegumeMix/Public/Player/LMPlayer.h index 2183e22..612e380 100644 --- a/Source/LegumeMix/Public/Player/LMPlayer.h +++ b/Source/LegumeMix/Public/Player/LMPlayer.h @@ -56,6 +56,7 @@ public: int RemoveAmmo(EAmmoType AmmoType, int Count) const; virtual bool CanJumpInternal_Implementation() const override; + virtual void OnJumped_Implementation() override; UFUNCTION(BlueprintCallable) void AddAmmo(EAmmoType Ammo, int AmmoCount); @@ -210,6 +211,9 @@ private: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix|LedgeGrab", meta = (AllowPrivateAccess = true, ClampMin = 0.f)) float LedgeGrabTraceLength = 44.f; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Legumix, meta = (AllowPrivateAccess = true, ClampMin = 0.01f)) + float CoyoteTimeLength = 0.5f; + /** * Actualize all parameters needed to calculate PlayerViewOcclusionPercent */ @@ -222,6 +226,9 @@ private: UFUNCTION(BlueprintCallable, Category=PostProcess) void SetPlayerViewOcclusionPercent(); + void OnWalkingOffLedge_Implementation(const FVector& PreviousFloorImpactNormal, const FVector& PreviousFloorContactNormal, const FVector& PreviousLocation, float TimeDelta) override; + void FinishCoyoteTime() { bIsInCoyoteTime = false; } + private: #if WITH_EDITORONLY_DATA /** If set, bullet debug will be drawn. */ @@ -232,4 +239,6 @@ private: private: FRandomStream SpreadStream; FTimerHandle LedgeGrabCheckTimer; + FTimerHandle CoyoteCheckTimer; + bool bIsInCoyoteTime; };