From ca617a8a3c8a7bb9464fa774585f87a975ac14dc Mon Sep 17 00:00:00 2001 From: baz Date: Sun, 15 Oct 2023 20:00:34 +0100 Subject: [PATCH] Spawn Particle System at Impact Point on a static object --- Source/Nakatomi/PlayerCharacter.cpp | 13 +++++++++++++ Source/Nakatomi/Weapon.cpp | 5 +++++ Source/Nakatomi/Weapon.h | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index 82ab14b..b730402 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -396,6 +396,19 @@ void APlayerCharacter::ProcessHits(TArray hits) rot.Yaw += 180.0f; decalActor->SetActorRotation(rot); } + + if (staticMeshComponent && !staticMeshComponent->IsSimulatingPhysics() && + CurrentWeapon->GetImpactParticleSystem()) + { + FTransform transform; + transform.SetLocation(Hit.ImpactPoint); + + UGameplayStatics::SpawnEmitterAtLocation(this, + CurrentWeapon->GetImpactParticleSystem(), + transform.GetLocation(), + FRotator::ZeroRotator, + true); + } } } } diff --git a/Source/Nakatomi/Weapon.cpp b/Source/Nakatomi/Weapon.cpp index 377f647..da7c20e 100644 --- a/Source/Nakatomi/Weapon.cpp +++ b/Source/Nakatomi/Weapon.cpp @@ -125,6 +125,11 @@ TSubclassOf AWeapon::GetDecalActor() return DecalActor; } +UParticleSystem* AWeapon::GetImpactParticleSystem() +{ + return ImpactParticleSystem; +} + TSubclassOf AWeapon::GetFieldSystemActor() { return FieldSystemActor; diff --git a/Source/Nakatomi/Weapon.h b/Source/Nakatomi/Weapon.h index d1901f1..ddc9bdd 100644 --- a/Source/Nakatomi/Weapon.h +++ b/Source/Nakatomi/Weapon.h @@ -55,6 +55,9 @@ protected: UPROPERTY(EditDefaultsOnly) TSubclassOf DecalActor; + UPROPERTY(EditDefaultsOnly) + UParticleSystem* ImpactParticleSystem; + public: // Sets default values for this actor's properties AWeapon(); @@ -101,4 +104,6 @@ public: TSubclassOf GetWeaponThrowableTemplate(); TSubclassOf GetDecalActor(); + + UParticleSystem* GetImpactParticleSystem(); };