From 4cb72bb499ed2f8432e4c81c4fe127702abb1931 Mon Sep 17 00:00:00 2001 From: TjgL Date: Wed, 12 Mar 2025 11:34:48 +0100 Subject: [PATCH] Implemented slide inputs Signed-off-by: TjgL --- .../Legumix/Player/BP_PlayerController.uasset | 4 ++-- Content/Legumix/Player/Input/IA_Slide.uasset | 3 +++ Content/Legumix/Player/Input/IMC_Default.uasset | 4 ++-- .../Private/Player/LMMovementComponent.cpp | 7 +++++-- .../Private/Player/LMPlayerController.cpp | 16 ++++++++++++++++ .../Public/Player/LMMovementComponent.h | 8 +++++--- .../LegumeMix/Public/Player/LMPlayerController.h | 6 ++++++ 7 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 Content/Legumix/Player/Input/IA_Slide.uasset diff --git a/Content/Legumix/Player/BP_PlayerController.uasset b/Content/Legumix/Player/BP_PlayerController.uasset index c402d84..12d2476 100644 --- a/Content/Legumix/Player/BP_PlayerController.uasset +++ b/Content/Legumix/Player/BP_PlayerController.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:504abdca2dc1731389651a842f3516c2512c3ef3652815c8b38fdbbe54d2b7cf -size 22113 +oid sha256:fc92081abb28b81e9a56e981284c3e7802f559c318716fe4c5d2f2bba749c6e3 +size 22303 diff --git a/Content/Legumix/Player/Input/IA_Slide.uasset b/Content/Legumix/Player/Input/IA_Slide.uasset new file mode 100644 index 0000000..db3c2b8 --- /dev/null +++ b/Content/Legumix/Player/Input/IA_Slide.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:038f57ce28cb8a93ff67bf7170ad62bbea268dd9c23ad31e8d2f2704ec0b91f6 +size 1387 diff --git a/Content/Legumix/Player/Input/IMC_Default.uasset b/Content/Legumix/Player/Input/IMC_Default.uasset index 4b3c94f..46ed3f6 100644 --- a/Content/Legumix/Player/Input/IMC_Default.uasset +++ b/Content/Legumix/Player/Input/IMC_Default.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e6f482de1b0f1d01b8addd6aa98e2bb9a0ad4213e5de92813b461299370dd4a5 -size 9979 +oid sha256:d0ff97e52ef57a81cb0874011e2cb04e2b80d485e8b65ef64bff423e0dd6611f +size 10659 diff --git a/Source/LegumeMix/Private/Player/LMMovementComponent.cpp b/Source/LegumeMix/Private/Player/LMMovementComponent.cpp index 5fbd0d6..bebd31b 100644 --- a/Source/LegumeMix/Private/Player/LMMovementComponent.cpp +++ b/Source/LegumeMix/Private/Player/LMMovementComponent.cpp @@ -116,11 +116,9 @@ bool ULMMovementComponent::CanCrouchInCurrentState() const void ULMMovementComponent::UpdateCharacterStateBeforeMovement(float DeltaSeconds) { - UE_LOG(LogTemp, Log, TEXT("Velocity %f vs %f"), Velocity.SizeSquared(), pow(SlideMinSpeed, 2)) if (MovementMode == EMovementMode::MOVE_Walking && Safe_bPrevWantsToCrouch) { FHitResult PotentialSlideSurface; - UE_LOG(LogTemp, Display, TEXT("PotentialSlideSurface")); if (Velocity.SizeSquared() > pow(SlideMinSpeed, 2) && GetSlideSurface(PotentialSlideSurface)) { EnterSlide(); @@ -260,5 +258,10 @@ void ULMMovementComponent::CrouchPressed() bWantsToCrouch = !bWantsToCrouch; } +void ULMMovementComponent::CrouchToggle(bool Toggle) +{ + bWantsToCrouch = Toggle; +} + #pragma endregion diff --git a/Source/LegumeMix/Private/Player/LMPlayerController.cpp b/Source/LegumeMix/Private/Player/LMPlayerController.cpp index 94eb9f8..06e4911 100644 --- a/Source/LegumeMix/Private/Player/LMPlayerController.cpp +++ b/Source/LegumeMix/Private/Player/LMPlayerController.cpp @@ -7,6 +7,7 @@ #include "LMUserSettings.h" #include "GameFramework/Character.h" #include "Kismet/GameplayStatics.h" +#include "Player/LMMovementComponent.h" #include "Player/LMPlayer.h" #include "Weapon/LMWeaponManager.h" @@ -35,6 +36,8 @@ void ALMPlayerController::SetupInputComponent() Input->BindAction(ReloadAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Reload); Input->BindAction(ScrollAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Scroll); Input->BindAction(PauseAction, ETriggerEvent::Triggered, this, &ALMPlayerController::TogglePause); + Input->BindAction(SlideAction, ETriggerEvent::Started, this, &ALMPlayerController::SlideInput); + Input->BindAction(SlideAction, ETriggerEvent::Completed, this, &ALMPlayerController::SlideCancel); } } @@ -79,6 +82,19 @@ void ALMPlayerController::PauseInput(const FInputActionValue& InputValue) TogglePause(); } +void ALMPlayerController::SlideInput(const FInputActionValue& InputValue) +{ + LegumixPlayer->GetLegumixMovementComponent()->CrouchToggle(true); +} + +void ALMPlayerController::SlideCancel(const FInputActionValue& InputValue) +{ + if (LegumixPlayer->GetLegumixMovementComponent()->bWantsToCrouch) + { + LegumixPlayer->GetLegumixMovementComponent()->CrouchToggle(false); + } +} + void ALMPlayerController::TogglePause() { const bool bIsPaused = UGameplayStatics::IsGamePaused(GetWorld()); diff --git a/Source/LegumeMix/Public/Player/LMMovementComponent.h b/Source/LegumeMix/Public/Player/LMMovementComponent.h index 5382b96..cd91f05 100644 --- a/Source/LegumeMix/Public/Player/LMMovementComponent.h +++ b/Source/LegumeMix/Public/Player/LMMovementComponent.h @@ -66,6 +66,11 @@ public: UFUNCTION(BlueprintPure) bool IsCustomMovementMode(ECustomMovementModes InCustomMovementMode) const; + UFUNCTION(BlueprintCallable, Category="Legumix|Slide") + void CrouchPressed(); + UFUNCTION(BlueprintCallable, Category="Legumix|Slide") + void CrouchToggle(bool Toggle); + public: UPROPERTY(Transient) TObjectPtr PlayerCharacterOwner; @@ -88,7 +93,4 @@ private: void ExitSlide(); void PhysSlide(float DeltaTime, int32 Iterations); bool GetSlideSurface(FHitResult& Hit) const; - - UFUNCTION(BlueprintCallable, Category="Legumix|Slide") - void CrouchPressed(); }; diff --git a/Source/LegumeMix/Public/Player/LMPlayerController.h b/Source/LegumeMix/Public/Player/LMPlayerController.h index 58f1ab6..8497837 100644 --- a/Source/LegumeMix/Public/Player/LMPlayerController.h +++ b/Source/LegumeMix/Public/Player/LMPlayerController.h @@ -47,9 +47,13 @@ private: UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = true)) TObjectPtr PauseAction; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = true)) + TObjectPtr SlideAction; UPROPERTY(BlueprintReadOnly, meta = (AllowPrivateAccess = true)) TObjectPtr LegumixPlayer; + virtual void SetupInputComponent() override; void Move(const FInputActionValue& InputValue); @@ -59,6 +63,8 @@ private: void Reload(const FInputActionValue& InputValue); void Scroll(const FInputActionValue& InputValue); void PauseInput(const FInputActionValue& InputValue); + void SlideInput(const FInputActionValue& InputValue); + void SlideCancel(const FInputActionValue& InputValue); UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true, UIMin=0.01, ClampMin=0.01, UIMax=10.0, ClampMax=10.0)) float Sensitivity = 1.0f;