From c9acf07ccdce77e68607ac780a19975e493f74b3 Mon Sep 17 00:00:00 2001 From: MH261677 Date: Thu, 30 Nov 2023 15:26:20 +0000 Subject: [PATCH] Added Stamina Consume To Jumping & Fixed Jumping Bugs --- .../Blueprints/BP_FirstPersonCharacter.uasset | 2 +- .../EndlessVendettaCharacter.cpp | 41 ++++++++++++------- .../EndlessVendettaCharacter.h | 4 ++ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset index af1aeccc..ea9b685a 100644 --- a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:29a9b2fccbf432819ea9a64b75f802f6b121dd5e7a2c34ada69ecf08057f1ace +oid sha256:58139ccad1a63dd9fa03404f0fb0b7af3f742d844b0ed7da0e081b96319600b9 size 54773 diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index 6e3adfb6..1fb28751 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -78,7 +78,6 @@ void AEndlessVendettaCharacter::Tick(float DeltaTime) { Super::Tick(DeltaTime); WeaponPickUpSystem(); - MoveGroundSpeed = Cast(GetComponentByClass(UMovementComponent::StaticClass()))->Velocity.Size(); if (MoveGroundSpeed > 0) @@ -91,11 +90,9 @@ void AEndlessVendettaCharacter::Tick(float DeltaTime) } if (bPressedJump) { - UE_LOG(LogTemp, Display, TEXT("Player Jumped")); if(CurrentStamina <= 0.0f) { CurrentStamina -= 20.0f; - UE_LOG(LogTemp, Display, TEXT("Current Stam: %f"), CurrentStamina); } } //PLAYER STAMINA HANDLING @@ -119,16 +116,6 @@ void AEndlessVendettaCharacter::Tick(float DeltaTime) } CurrentStamina += FMath::Clamp(StaminaRegenRate, 0.0f, 100.0f); } - //make your own jump and call the default character jump - // if (bPressedJump) - // { - // UE_LOG(LogTemp, Display, TEXT("Player Jumped")); - // if(CurrentStamina <= 0.0f) - // { - // CurrentStamina -= 20.0f; - // UE_LOG(LogTemp, Display, TEXT("Current Stam: %f"), CurrentStamina); - // } - // } } void AEndlessVendettaCharacter::RegenHealth() @@ -171,8 +158,8 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent* if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked(PlayerInputComponent)) { //Jumping - EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump); - EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping); + EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::Jumping); + EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &AEndlessVendettaCharacter::StopJump); //Moving EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::Move); @@ -576,6 +563,30 @@ void AEndlessVendettaCharacter::StopSprint() } } +void AEndlessVendettaCharacter::Jumping() +{ + if (CurrentStamina > 20.0f) + { + bHasPlayerJumped = true; + if (bHasPlayerJumped) + { + Super::Jump(); + if (!CharacterMovement->IsFalling()) + { + CurrentStamina -= 20.0f; + } + bHasPlayerJumped = false; + } + } +} + +void AEndlessVendettaCharacter::StopJump() +{ + Super::StopJumping(); + UE_LOG(LogTemp, Display, TEXT("Player has stopped jumping")); + bHasPlayerJumped = false; +} + void AEndlessVendettaCharacter::Look(const FInputActionValue& Value) { // input is a Vector2D diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h index ca2e5a99..8bfa7c05 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -175,6 +175,10 @@ public: void Sprint(); void StopSprint(); + void Jumping(); + void StopJump(); + bool bHasPlayerJumped = false; + UArrowComponent* ScopedLocationArrow; UPROPERTY(EditAnywhere, Category = "Dont Touch")