diff --git a/Content/Blueprints/Weapon/Projectiles/BP_Projectile.uasset b/Content/Blueprints/Weapon/Projectiles/BP_Projectile.uasset index e292354..42ee6dd 100644 Binary files a/Content/Blueprints/Weapon/Projectiles/BP_Projectile.uasset and b/Content/Blueprints/Weapon/Projectiles/BP_Projectile.uasset differ diff --git a/Source/Blaster/Weapon/Projectile.cpp b/Source/Blaster/Weapon/Projectile.cpp index 4b1a5a5..220ba11 100644 --- a/Source/Blaster/Weapon/Projectile.cpp +++ b/Source/Blaster/Weapon/Projectile.cpp @@ -6,6 +6,7 @@ #include "Components/BoxComponent.h" #include "GameFramework/ProjectileMovementComponent.h" #include "Kismet/GameplayStatics.h" +#include "Sound/SoundCue.h" AProjectile::AProjectile() { @@ -39,6 +40,31 @@ void AProjectile::BeginPlay() EAttachLocation::KeepWorldPosition ); } + + if (HasAuthority()) + { + CollisionBox->OnComponentHit.AddDynamic(this, &AProjectile::OnHit); + } +} + +void AProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) +{ + Destroy(); +} + +void AProjectile::Destroyed() +{ + Super::Destroyed(); + + if (ImpactParticles) + { + UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ImpactParticles, GetActorTransform()); + } + + if (ImpactSound) + { + UGameplayStatics::PlaySoundAtLocation(this, ImpactSound, GetActorLocation()); + } } void AProjectile::Tick(float DeltaTime) diff --git a/Source/Blaster/Weapon/Projectile.h b/Source/Blaster/Weapon/Projectile.h index adefdeb..53aebe2 100644 --- a/Source/Blaster/Weapon/Projectile.h +++ b/Source/Blaster/Weapon/Projectile.h @@ -18,8 +18,12 @@ public: protected: virtual void BeginPlay() override; - -public: + + UFUNCTION() + virtual void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit); + virtual void Destroyed() override; + +private: UPROPERTY(EditAnywhere) class UBoxComponent* CollisionBox; @@ -31,4 +35,10 @@ public: class UParticleSystem* Tracer; class UParticleSystemComponent* TracerComponent; + + UPROPERTY(EditAnywhere) + UParticleSystem* ImpactParticles; + + UPROPERTY(EditAnywhere) + class USoundCue* ImpactSound; };