From c372d9e8d5866fa1a6c08ac773bb8fb4fc63d4bd Mon Sep 17 00:00:00 2001 From: Kubson96 <42842162+Kubson96@users.noreply.github.com> Date: Fri, 4 Apr 2025 19:53:32 +0200 Subject: [PATCH] feat: slower movement when aiming When player aiming, sprint isn't possible and walk speed is reduced to 70% --- .../Characters/Components/ShootingComponent.cpp | 8 +++++++- Source/Exo/Private/Player/ExoPlayerController.cpp | 14 ++++++++++---- .../Characters/Components/ShootingComponent.h | 8 ++++++-- Source/Exo/Public/Characters/ExoPlayerCharacter.h | 3 +++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Source/Exo/Private/Characters/Components/ShootingComponent.cpp b/Source/Exo/Private/Characters/Components/ShootingComponent.cpp index 6639f7e..80711e7 100644 --- a/Source/Exo/Private/Characters/Components/ShootingComponent.cpp +++ b/Source/Exo/Private/Characters/Components/ShootingComponent.cpp @@ -191,12 +191,18 @@ void UShootingComponent::StartAiming() { if (IsValid(CurrentGun)) { + PlayerCharacter->bIsAimingMode = true; + PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed * AimingMoveSpeedScale; + TargetFOV = CurrentGun->AimingFOV; } } void UShootingComponent::StopAiming() { + PlayerCharacter->bIsAimingMode = false; + PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed; + TargetFOV = DefaultFOV; } @@ -206,6 +212,6 @@ void UShootingComponent::TickComponent(float DeltaTime, ELevelTick TickType, FAc Super::TickComponent(DeltaTime, TickType, ThisTickFunction); float CurrentFOV = CameraManager->GetFOVAngle(); - float NewFOV = FMath::FInterpTo(CurrentFOV, TargetFOV, DeltaTime, AimingSpeed); + float NewFOV = FMath::FInterpTo(CurrentFOV, TargetFOV, DeltaTime, AimingAnimationSpeed); CameraManager->SetFOV(NewFOV); } diff --git a/Source/Exo/Private/Player/ExoPlayerController.cpp b/Source/Exo/Private/Player/ExoPlayerController.cpp index 83811d9..3a15caf 100644 --- a/Source/Exo/Private/Player/ExoPlayerController.cpp +++ b/Source/Exo/Private/Player/ExoPlayerController.cpp @@ -143,16 +143,22 @@ void AExoPlayerController::PlayerStopCrouch() void AExoPlayerController::PlayerStartSprint() { - UE_LOG(LogTemp, Display, TEXT("Start sprint")); + if (!PlayerCharacter->bIsAimingMode) + { + UE_LOG(LogTemp, Display, TEXT("Start sprint")); - PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->SprintSpeed; + PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->SprintSpeed; + } } void AExoPlayerController::PlayerStopSprint() { - UE_LOG(LogTemp, Display, TEXT("Stop sprint")); + if (!PlayerCharacter->bIsAimingMode) + { + UE_LOG(LogTemp, Display, TEXT("Stop sprint")); - PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed; + PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed; + } } void AExoPlayerController::PlayerShoot() diff --git a/Source/Exo/Public/Characters/Components/ShootingComponent.h b/Source/Exo/Public/Characters/Components/ShootingComponent.h index 04ded36..25eb3ce 100644 --- a/Source/Exo/Public/Characters/Components/ShootingComponent.h +++ b/Source/Exo/Public/Characters/Components/ShootingComponent.h @@ -5,6 +5,7 @@ #include "CoreMinimal.h" #include "Components/ActorComponent.h" #include +#include "GameFramework/CharacterMovementComponent.h" #include #include "Interfaces/Damageable.h" #include "ShootingComponent.generated.h" @@ -63,8 +64,11 @@ public: UFUNCTION(Category = "Shooting") void StopAiming(); - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shooting") - float AimingSpeed = 30.0f; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Aiming") + float AimingAnimationSpeed = 30.0f; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Aiming") + float AimingMoveSpeedScale = 0.70f; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shooting") float DropGunRange = 20.0f; diff --git a/Source/Exo/Public/Characters/ExoPlayerCharacter.h b/Source/Exo/Public/Characters/ExoPlayerCharacter.h index 5c290f0..349e9b5 100644 --- a/Source/Exo/Public/Characters/ExoPlayerCharacter.h +++ b/Source/Exo/Public/Characters/ExoPlayerCharacter.h @@ -35,6 +35,9 @@ public: UPROPERTY(EditAnywhere, Category = "Movement Properties") float SprintSpeed = 1500.0f; + UPROPERTY(EditAnywhere, Category = "Aiming") + float bIsAimingMode = false; + protected: virtual void BeginPlay() override;