Merge branch 'player-movement' into dev

This commit is contained in:
MH261677 2023-11-30 16:03:54 +00:00
commit 2d7091dee9
6 changed files with 127 additions and 11 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -69,14 +69,15 @@ void AEndlessVendettaCharacter::BeginPlay()
}
InventoryComponent = Cast<UInventoryComponent>(GetWorld()->GetFirstPlayerController()->GetComponentByClass(UInventoryComponent::StaticClass()));
WalkSpeed = CharacterMovement->MaxWalkSpeed;
OriginalWalkSpeed = CharacterMovement->MaxWalkSpeed;
CurrentStamina = MaxStamina;
}
void AEndlessVendettaCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
WeaponPickUpSystem();
MoveGroundSpeed = Cast<UMovementComponent>(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<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);
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

View File

@ -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")