178 - Client-Side Predicting Aiming

This commit is contained in:
Kingsmedia 2022-05-26 16:50:36 +02:00
parent 41a200110b
commit 58a06d4366
2 changed files with 16 additions and 2 deletions

View File

@ -760,6 +760,7 @@ void UCombatComponent::SetAiming(bool bIsAiming)
{ {
Character->ShowSniperScopeWidget(bIsAiming); Character->ShowSniperScopeWidget(bIsAiming);
} }
if (Character->IsLocallyControlled()) bAimButtonPressed = bIsAiming;
} }
void UCombatComponent::ServerSetAiming_Implementation(bool 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() bool UCombatComponent::CanFire()
{ {
if (PrimaryWeapon == nullptr) return false; if (PrimaryWeapon == nullptr) return false;

View File

@ -120,8 +120,13 @@ private:
UPROPERTY(ReplicatedUsing=OnRep_SecondaryWeapon) UPROPERTY(ReplicatedUsing=OnRep_SecondaryWeapon)
AWeapon* SecondaryWeapon; AWeapon* SecondaryWeapon;
UPROPERTY(Replicated) UPROPERTY(ReplicatedUsing = OnRep_Aiming)
bool bAiming; bool bAiming = false;
bool bAimButtonPressed = false;
UFUNCTION()
void OnRep_Aiming();
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
float BaseWalkSpeed; float BaseWalkSpeed;