From 58a06d43668f1d4fcc88be95a3edfe138cf39646 Mon Sep 17 00:00:00 2001 From: Kingsmedia Date: Thu, 26 May 2022 16:50:36 +0200 Subject: [PATCH] 178 - Client-Side Predicting Aiming --- Source/Blaster/Components/CombatComponent.cpp | 9 +++++++++ Source/Blaster/Components/CombatComponent.h | 9 +++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index 47b1890..7427e1c 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -760,6 +760,7 @@ void UCombatComponent::SetAiming(bool bIsAiming) { Character->ShowSniperScopeWidget(bIsAiming); } + if (Character->IsLocallyControlled()) bAimButtonPressed = bIsAiming; } void UCombatComponent::ServerSetAiming_Implementation(bool bIsAiming) @@ -771,6 +772,14 @@ void UCombatComponent::ServerSetAiming_Implementation(bool bIsAiming) } } +void UCombatComponent::OnRep_Aiming() +{ + if (Character && Character->IsLocallyControlled()) + { + bAiming = bAimButtonPressed; + } +} + bool UCombatComponent::CanFire() { if (PrimaryWeapon == nullptr) return false; diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index 333057c..54444a5 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -120,8 +120,13 @@ private: UPROPERTY(ReplicatedUsing=OnRep_SecondaryWeapon) AWeapon* SecondaryWeapon; - UPROPERTY(Replicated) - bool bAiming; + UPROPERTY(ReplicatedUsing = OnRep_Aiming) + bool bAiming = false; + + bool bAimButtonPressed = false; + + UFUNCTION() + void OnRep_Aiming(); UPROPERTY(EditAnywhere) float BaseWalkSpeed;