Populated Sprint and UnSprint Functions
This commit is contained in:
parent
08e7fcecba
commit
92ab1c3d6b
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:b286c36bff935d0bb4a21224449c4dbd84f2dd72c29fb14da3e97822f0a9c9d0
|
||||
size 54078
|
||||
oid sha256:017155c3e85841098dd90809087103d777592a4dc37f146560ab46b4910a522c
|
||||
size 54599
|
||||
|
@ -69,6 +69,8 @@ void AEndlessVendettaCharacter::BeginPlay()
|
||||
}
|
||||
|
||||
InventoryComponent = Cast<UInventoryComponent>(GetWorld()->GetFirstPlayerController()->GetComponentByClass(UInventoryComponent::StaticClass()));
|
||||
WalkSpeed = CharacterMovement->MaxWalkSpeed;
|
||||
OriginalWalkSpeed = CharacterMovement->MaxWalkSpeed;
|
||||
}
|
||||
|
||||
void AEndlessVendettaCharacter::Tick(float DeltaTime)
|
||||
@ -134,7 +136,8 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent*
|
||||
|
||||
//Moving
|
||||
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::Move);
|
||||
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::Sprint);
|
||||
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);
|
||||
@ -431,17 +434,6 @@ void AEndlessVendettaCharacter::StopFire()
|
||||
}
|
||||
}
|
||||
|
||||
void AEndlessVendettaCharacter::Sprint()
|
||||
{
|
||||
MoveGroundSpeed *= 2;
|
||||
// bIsPlayerSprinting = true;
|
||||
// if (bIsPlayerSprinting)
|
||||
// {
|
||||
// MoveGroundSpeed *= 2;
|
||||
// bIsPlayerSprinting = false;
|
||||
// }
|
||||
}
|
||||
|
||||
void AEndlessVendettaCharacter::GunRightClick()
|
||||
{
|
||||
if (IsValid(PrimaryWeapon) && !bIsScoped)
|
||||
@ -523,6 +515,33 @@ void AEndlessVendettaCharacter::Move(const FInputActionValue& Value)
|
||||
}
|
||||
}
|
||||
|
||||
void AEndlessVendettaCharacter::Sprint()
|
||||
{
|
||||
bIsPlayerSprinting = true;
|
||||
if (bIsPlayerSprinting)
|
||||
{
|
||||
CharacterMovement->MaxWalkSpeed = SprintSpeed;
|
||||
MaxStamina -= StaminaDecreaseRate;
|
||||
UE_LOG(LogTemp, Display, TEXT("Walk Speed: %f"), WalkSpeed);
|
||||
if (MaxStamina <= 0)
|
||||
{
|
||||
CharacterMovement->MaxWalkSpeed = OriginalWalkSpeed;
|
||||
bIsPlayerSprinting = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AEndlessVendettaCharacter::StopSprint()
|
||||
{
|
||||
bIsPlayerSprinting = false;
|
||||
if (!bIsPlayerSprinting)
|
||||
{
|
||||
UE_LOG(LogTemp, Display, TEXT("Player stopped sprinting"));
|
||||
CharacterMovement->MaxWalkSpeed = OriginalWalkSpeed;
|
||||
MaxStamina++;
|
||||
}
|
||||
}
|
||||
|
||||
void AEndlessVendettaCharacter::Look(const FInputActionValue& Value)
|
||||
{
|
||||
// input is a Vector2D
|
||||
|
@ -86,12 +86,18 @@ public:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats")
|
||||
float DefaultHealth = 100.0f;
|
||||
|
||||
//STAMINA AND SPRINT SPEED
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats")
|
||||
float MaxStamina = 100.0f;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats")
|
||||
float StaminaDecreaseRate = 10.0f;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats")
|
||||
int SprintSpeed = 50;
|
||||
float SprintSpeed = 1200;
|
||||
|
||||
//Getting the charMovementComp
|
||||
UCharacterMovementComponent* CharacterMovement = GetCharacterMovement();
|
||||
float WalkSpeed;
|
||||
float OriginalWalkSpeed;
|
||||
|
||||
AActor* PrimaryWeaponActor;
|
||||
AActor* SecondaryWeaponActor;
|
||||
@ -117,6 +123,7 @@ public:
|
||||
|
||||
bool bIsPlayerMoving = false;
|
||||
|
||||
UPROPERTY(VisibleAnywhere)
|
||||
bool bIsPlayerSprinting = false;
|
||||
|
||||
double MoveGroundSpeed;
|
||||
@ -162,6 +169,7 @@ public:
|
||||
void StopFire();
|
||||
|
||||
void Sprint();
|
||||
void StopSprint();
|
||||
|
||||
UArrowComponent* ScopedLocationArrow;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user