diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset index 68f6e73f..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:b0a493fd95d8b0b43306329298c058cfa2f164ec071457bc575a8eafee95f1b1 -size 53936 +oid sha256:58139ccad1a63dd9fa03404f0fb0b7af3f742d844b0ed7da0e081b96319600b9 +size 54773 diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/WBP_Crosshair.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/WBP_Crosshair.uasset index 939e70d9..29ebde67 100644 --- a/EndlessVendetta/Content/FirstPerson/Blueprints/WBP_Crosshair.uasset +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/WBP_Crosshair.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:13ff21aa89e2ded711aff8ee6617abc2d565d222c39ce3878969fdfe44d5a81f -size 75992 +oid sha256:8ac7733948c885fda46dd009dd75dfe5c79abf1262e9aadcf17c401bb8f64ecf +size 93512 diff --git a/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Sprint.uasset b/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Sprint.uasset new file mode 100644 index 00000000..1a2ea734 --- /dev/null +++ b/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Sprint.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6e25b72a06c43ac63140b164e9ee5e2a8222f021ac5bd045149a27c2d8f073a1 +size 1360 diff --git a/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset b/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset index 6f199667..4764655f 100644 --- a/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset +++ b/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:750ab013f24a45539806fd40e9cd2a328ff31b40c5d3edcce0676fb3bf6935ee -size 18664 +oid sha256:8576231cc54d32ecfa8c00c7570ec51bb9d741dabc85bc0b4ef684bbc8209d04 +size 19248 diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index 04a8f415..438d89e8 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -69,14 +69,15 @@ void AEndlessVendettaCharacter::BeginPlay() } InventoryComponent = Cast(GetWorld()->GetFirstPlayerController()->GetComponentByClass(UInventoryComponent::StaticClass())); + WalkSpeed = CharacterMovement->MaxWalkSpeed; + OriginalWalkSpeed = CharacterMovement->MaxWalkSpeed; + CurrentStamina = MaxStamina; } void AEndlessVendettaCharacter::Tick(float DeltaTime) { Super::Tick(DeltaTime); - WeaponPickUpSystem(); - MoveGroundSpeed = Cast(GetComponentByClass(UMovementComponent::StaticClass()))->Velocity.Size(); if (MoveGroundSpeed > 0) @@ -85,8 +86,40 @@ void AEndlessVendettaCharacter::Tick(float DeltaTime) } else if (MoveGroundSpeed <= 0) { + this->GetFirstPersonCameraComponent()->SetFieldOfView(90); bIsPlayerMoving = false; } + if (bPressedJump) + { + if(CurrentStamina <= 0.0f) + { + CurrentStamina -= 20.0f; + } + } + //PLAYER STAMINA HANDLING + if (MoveGroundSpeed > 0) + { + if (bIsPlayerSprinting) + { + CurrentStamina -= FMath::Clamp(StaminaDecreaseRate, 0.0f, 100.0f); + if (CurrentStamina <= 0.0f) + { + bIsPlayerSprinting = false; + this->GetFirstPersonCameraComponent()->SetFieldOfView(90); + CurrentStamina = 0.0f; + CharacterMovement->MaxWalkSpeed = OriginalWalkSpeed; + } + } + } + if (!bIsPlayerSprinting) + { + if(CurrentStamina >= 100.0f) + { + CurrentStamina = 100.0f; + return; + } + CurrentStamina += FMath::Clamp(StaminaRegenRate, 0.0f, 100.0f); + } } void AEndlessVendettaCharacter::RegenHealth() @@ -129,11 +162,13 @@ 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); + EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::Sprint); + EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Completed, this, &AEndlessVendettaCharacter::StopSprint); //Looking EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::Look); @@ -511,6 +546,54 @@ void AEndlessVendettaCharacter::Move(const FInputActionValue& Value) } } +void AEndlessVendettaCharacter::Sprint() +{ + bIsPlayerSprinting = true; + if (bIsPlayerSprinting) + { + if (MoveGroundSpeed > 0) + { + CharacterMovement->MaxWalkSpeed = SprintSpeed; + this->GetFirstPersonCameraComponent()->SetFieldOfView(100); + } + } +} + +void AEndlessVendettaCharacter::StopSprint() +{ + bIsPlayerSprinting = false; + if (!bIsPlayerSprinting) + { + UE_LOG(LogTemp, Display, TEXT("Player stopped sprinting")); + CharacterMovement->MaxWalkSpeed = OriginalWalkSpeed; + this->GetFirstPersonCameraComponent()->SetFieldOfView(90); + } +} + +void AEndlessVendettaCharacter::Jumping() +{ + if (CurrentStamina > 10.0f) + { + bHasPlayerJumped = true; + if (bHasPlayerJumped) + { + Super::Jump(); + if (!CharacterMovement->IsFalling()) + { + CurrentStamina -= 10.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 9a14b875..8bfa7c05 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -73,6 +73,9 @@ class AEndlessVendettaCharacter : public ACharacter UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) UInputAction* InteractAction; + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) + UInputAction* SprintAction; + public: AEndlessVendettaCharacter(); @@ -83,6 +86,23 @@ public: UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats") float DefaultHealth = 100.0f; + //STAMINA AND SPRINT SPEED + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats") + float MaxStamina = 100; + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats") + float CurrentStamina; + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats") + float StaminaDecreaseRate = 0.2; + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats") + float StaminaRegenRate = 0.05; + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats") + float SprintSpeed = 900; + + //Getting the charMovementComp + UCharacterMovementComponent* CharacterMovement = GetCharacterMovement(); + float WalkSpeed; + float OriginalWalkSpeed; + AActor* PrimaryWeaponActor; AActor* SecondaryWeaponActor; bool bIsPrimaryWeaponCreated = false; @@ -107,6 +127,9 @@ public: bool bIsPlayerMoving = false; + UPROPERTY(VisibleAnywhere) + bool bIsPlayerSprinting = false; + double MoveGroundSpeed; /** Look Input Action */ @@ -149,6 +172,13 @@ public: UFUNCTION(BlueprintCallable, Category = "Weapons") void StopFire(); + void Sprint(); + void StopSprint(); + + void Jumping(); + void StopJump(); + bool bHasPlayerJumped = false; + UArrowComponent* ScopedLocationArrow; UPROPERTY(EditAnywhere, Category = "Dont Touch")