151 - Grenades in Multiplayer

This commit is contained in:
Kingsmedia 2022-05-22 14:26:02 +02:00
parent 5c1967bdaa
commit 899f058596
2 changed files with 13 additions and 2 deletions

View File

@ -315,10 +315,18 @@ void UCombatComponent::ThrowGrenadeFinished()
void UCombatComponent::LaunchGrenade() void UCombatComponent::LaunchGrenade()
{ {
ShowAttachedGrenade(false); ShowAttachedGrenade(false);
if (Character && Character->HasAuthority() && GrenadeClass && Character->GetAttachedGrenade()) if (Character && Character->IsLocallyControlled())
{
ServerLaunchGrenade(HitTarget);
}
}
void UCombatComponent::ServerLaunchGrenade_Implementation(const FVector_NetQuantize& Target)
{
if (Character && GrenadeClass && Character->GetAttachedGrenade())
{ {
const FVector StartingLocation = Character->GetAttachedGrenade()->GetComponentLocation(); const FVector StartingLocation = Character->GetAttachedGrenade()->GetComponentLocation();
FVector ToTarget = HitTarget - StartingLocation; FVector ToTarget = Target - StartingLocation;
FActorSpawnParameters SpawnParams; FActorSpawnParameters SpawnParams;
SpawnParams.Owner = Character; SpawnParams.Owner = Character;
SpawnParams.Instigator = Character; SpawnParams.Instigator = Character;

View File

@ -39,6 +39,9 @@ public:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void LaunchGrenade(); void LaunchGrenade();
UFUNCTION(Server, Reliable)
void ServerLaunchGrenade(const FVector_NetQuantize& Target);
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;