Added Stamina Consume To Jumping & Fixed Jumping Bugs

This commit is contained in:
MH261677 2023-11-30 15:26:20 +00:00
parent 91f9003ff0
commit c9acf07ccd
3 changed files with 31 additions and 16 deletions

View File

@ -78,7 +78,6 @@ void AEndlessVendettaCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
WeaponPickUpSystem();
MoveGroundSpeed = Cast<UMovementComponent>(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<UEnhancedInputComponent>(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

View File

@ -175,6 +175,10 @@ public:
void Sprint();
void StopSprint();
void Jumping();
void StopJump();
bool bHasPlayerJumped = false;
UArrowComponent* ScopedLocationArrow;
UPROPERTY(EditAnywhere, Category = "Dont Touch")