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;