149 - Showing the Attached Grenade

This commit is contained in:
Kingsmedia 2022-05-21 17:03:30 +02:00
parent 2376723209
commit d114ceb1fb
8 changed files with 25 additions and 1 deletions

View File

@ -59,7 +59,6 @@ ABlasterCharacter::ABlasterCharacter()
AttachedGrenade = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Attached Grenade"));
AttachedGrenade->SetupAttachment(GetMesh(), FName("RightHandThrowableSocket"));
AttachedGrenade->SetCollisionEnabled(ECollisionEnabled::NoCollision);
}
void ABlasterCharacter::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
@ -184,6 +183,10 @@ void ABlasterCharacter::BeginPlay()
{
OnTakeAnyDamage.AddDynamic(this, &ABlasterCharacter::ReceiveDamage);
}
if (AttachedGrenade)
{
AttachedGrenade->SetVisibility(false);
}
}
void ABlasterCharacter::Tick(float DeltaTime)

View File

@ -208,4 +208,5 @@ public:
FORCEINLINE UCombatComponent* GetCombat() const { return Combat; }
FORCEINLINE bool GetDisableGameplay() const { return bDisableGameplay; }
FORCEINLINE UAnimMontage* GetReloadMontage() const { return ReloadMontage; }
FORCEINLINE UStaticMeshComponent* GetAttachedGrenade() const { return AttachedGrenade; }
};

View File

@ -312,6 +312,11 @@ void UCombatComponent::ThrowGrenadeFinished()
AttachActorToRightHand(EquippedWeapon);
}
void UCombatComponent::LaunchGrenade()
{
ShowAttachedGrenade(false);
}
void UCombatComponent::OnRep_CombatState()
{
switch (CombatState)
@ -330,6 +335,7 @@ void UCombatComponent::OnRep_CombatState()
{
Character->PlayThrowGrenadeMontage();
AttachActorToLeftHand(EquippedWeapon);
ShowAttachedGrenade(true);
}
break;
}
@ -362,6 +368,7 @@ void UCombatComponent::ThrowGrenade()
{
Character->PlayThrowGrenadeMontage();
AttachActorToLeftHand(EquippedWeapon);
ShowAttachedGrenade(true);
}
if (Character && !Character->HasAuthority())
{
@ -376,6 +383,15 @@ void UCombatComponent::ServerThrowGrenade_Implementation()
{
Character->PlayThrowGrenadeMontage();
AttachActorToLeftHand(EquippedWeapon);
ShowAttachedGrenade(true);
}
}
void UCombatComponent::ShowAttachedGrenade(bool bShowGrenade)
{
if (Character && Character->GetAttachedGrenade())
{
Character->GetAttachedGrenade()->SetVisibility(bShowGrenade);
}
}

View File

@ -36,6 +36,9 @@ public:
UFUNCTION(BlueprintCallable)
void ThrowGrenadeFinished();
UFUNCTION(BlueprintCallable)
void LaunchGrenade();
protected:
virtual void BeginPlay() override;
void SetAiming(bool bIsAiming);
@ -74,6 +77,7 @@ protected:
void UpdateCarriedAmmo();
void PlayEquipWeaponSound();
void ReloadEmptyWeapon();
void ShowAttachedGrenade(bool bShowGrenade);
private:
UPROPERTY()
class ABlasterCharacter* Character;