From dff53980f9e50cae292b5c2016a1e4435be45756 Mon Sep 17 00:00:00 2001 From: Kingsmedia Date: Thu, 5 May 2022 22:13:12 +0200 Subject: [PATCH] 85 - Shrink Crosshairs when Aiming --- Source/Blaster/Components/CombatComponent.cpp | 24 ++++++++++++++++++- Source/Blaster/Components/CombatComponent.h | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index 13a6d3b..9d7bffd 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -107,7 +107,24 @@ void UCombatComponent::SetHUDCrosshairs(float DeltaTime) CrosshairInAirFactor = FMath::FInterpTo(CrosshairInAirFactor, 0.f, DeltaTime, 30.f); } - HUDPackage.CrosshairSpread = CrosshairVelocityFactor + CrosshairInAirFactor; + if (bAiming) + { + CrosshairAimFactor = FMath::FInterpTo(CrosshairAimFactor, 0.58f, DeltaTime, 30.f); + } + else + { + CrosshairAimFactor = FMath::FInterpTo(CrosshairAimFactor, 0.f, DeltaTime, 30.f); + } + + CrosshairShootingFactor = FMath::FInterpTo(CrosshairShootingFactor, 0.f, DeltaTime, 40.f); + + HUDPackage.CrosshairSpread = + 0.5f + + CrosshairVelocityFactor + + CrosshairInAirFactor - + CrosshairAimFactor + + CrosshairShootingFactor; + HUD->SetHUDPackage(HUDPackage); } } @@ -168,6 +185,11 @@ void UCombatComponent::FireButtonPressed(bool bPressed) FHitResult HitResult; TraceUnderCrosshairs(HitResult); ServerFire(HitResult.ImpactPoint); + + if (EquippedWeapon) + { + CrosshairShootingFactor = 0.75f; + } } } diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index bf5f7ea..a289baa 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -66,6 +66,8 @@ private: //HUD and Crosshairs float CrosshairVelocityFactor; float CrosshairInAirFactor; + float CrosshairAimFactor; + float CrosshairShootingFactor; // Aiming and FOV