From c26dcd6eae183c82efc83b33799f0aff0fc00406 Mon Sep 17 00:00:00 2001 From: Kubson96 <42842162+Kubson96@users.noreply.github.com> Date: Sat, 22 Feb 2025 20:33:07 +0100 Subject: [PATCH] fix: improved recoil Recoil now based on camera move instead of applying forces on player character --- .../Private/Characters/Components/ShootingComponent.cpp | 7 +++++-- .../Exo/Public/Characters/Components/ShootingComponent.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/Exo/Private/Characters/Components/ShootingComponent.cpp b/Source/Exo/Private/Characters/Components/ShootingComponent.cpp index 713da6d..1945e58 100644 --- a/Source/Exo/Private/Characters/Components/ShootingComponent.cpp +++ b/Source/Exo/Private/Characters/Components/ShootingComponent.cpp @@ -51,8 +51,11 @@ void UShootingComponent::Shoot() PlayerCharacter->GetWorldTimerManager().SetTimer(ShootCooldownTimer, this, &UShootingComponent::ResetFireCooldown, FireRateCooldown, false); // Odrzut - FVector RecoilDirection = -PlayerCharacter->GetActorForwardVector(); - PlayerCharacter->LaunchCharacter(RecoilDirection * RecoilForce, true, false); + float RecoilPitch = FMath::RandRange(-1.0f, -0.5f); + float RecoilYaw = FMath::RandRange(-0.5f, 0.5f); + + PlayerCharacter->AddControllerPitchInput(RecoilPitch * RecoilForceMultiplier); + PlayerCharacter->AddControllerYawInput(RecoilYaw * RecoilForceMultiplier); // DEBUG if (bShowDebugLine) diff --git a/Source/Exo/Public/Characters/Components/ShootingComponent.h b/Source/Exo/Public/Characters/Components/ShootingComponent.h index b83de10..6f66409 100644 --- a/Source/Exo/Public/Characters/Components/ShootingComponent.h +++ b/Source/Exo/Public/Characters/Components/ShootingComponent.h @@ -28,7 +28,7 @@ public: float FireRateCooldown = 1.0f; UPROPERTY(EditAnywhere, Category = "Shooting") - float RecoilForce = 50.0f; + float RecoilForceMultiplier = 1.0f; UPROPERTY(EditAnywhere, Category = "Shooting") float ReloadTime = 3.0f;