diff --git a/Content/Assets/FX/RocketTrail/NS_TrailSmoke.uasset b/Content/Assets/FX/RocketTrail/NS_TrailSmoke.uasset index 5185142..9964556 100644 Binary files a/Content/Assets/FX/RocketTrail/NS_TrailSmoke.uasset and b/Content/Assets/FX/RocketTrail/NS_TrailSmoke.uasset differ diff --git a/Content/Assets/MilitaryWeapSilver/Sound/RocketLauncher/Cues/RocketLauncher_InAirLoop_Cue.uasset b/Content/Assets/MilitaryWeapSilver/Sound/RocketLauncher/Cues/RocketLauncher_InAirLoop_Cue.uasset index 5c9720a..7e6550c 100644 Binary files a/Content/Assets/MilitaryWeapSilver/Sound/RocketLauncher/Cues/RocketLauncher_InAirLoop_Cue.uasset and b/Content/Assets/MilitaryWeapSilver/Sound/RocketLauncher/Cues/RocketLauncher_InAirLoop_Cue.uasset differ diff --git a/Content/Blueprints/Weapon/Projectiles/BP_Rocket.uasset b/Content/Blueprints/Weapon/Projectiles/BP_Rocket.uasset index 9609a36..a1cc191 100644 Binary files a/Content/Blueprints/Weapon/Projectiles/BP_Rocket.uasset and b/Content/Blueprints/Weapon/Projectiles/BP_Rocket.uasset differ diff --git a/Source/Blaster/Blaster.Build.cs b/Source/Blaster/Blaster.Build.cs index 7e92c8c..79aa606 100644 --- a/Source/Blaster/Blaster.Build.cs +++ b/Source/Blaster/Blaster.Build.cs @@ -8,7 +8,7 @@ public class Blaster : ModuleRules { PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; - PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "MultiplayerSessions", "OnlineSubsystem", "OnlineSubsystemSteam" }); + PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Niagara" }); PrivateDependencyModuleNames.AddRange(new string[] { }); diff --git a/Source/Blaster/Weapon/Projectile.h b/Source/Blaster/Weapon/Projectile.h index efafd8c..3bdc169 100644 --- a/Source/Blaster/Weapon/Projectile.h +++ b/Source/Blaster/Weapon/Projectile.h @@ -25,12 +25,18 @@ protected: UPROPERTY(EditAnywhere) float Damage = 20.f; - -private: UPROPERTY(EditAnywhere) - class UBoxComponent* CollisionBox; + class UParticleSystem* ImpactParticles; + UPROPERTY(EditAnywhere) + class USoundCue* ImpactSound; + + UPROPERTY(EditAnywhere) + class UBoxComponent* CollisionBox; + +private: + UPROPERTY(VisibleAnywhere) class UProjectileMovementComponent* ProjectileMovementComponent; @@ -39,10 +45,4 @@ private: UPROPERTY() class UParticleSystemComponent* TracerComponent; - - UPROPERTY(EditAnywhere) - UParticleSystem* ImpactParticles; - - UPROPERTY(EditAnywhere) - class USoundCue* ImpactSound; }; diff --git a/Source/Blaster/Weapon/ProjectileRocket.cpp b/Source/Blaster/Weapon/ProjectileRocket.cpp index 8d79d68..45c61e1 100644 --- a/Source/Blaster/Weapon/ProjectileRocket.cpp +++ b/Source/Blaster/Weapon/ProjectileRocket.cpp @@ -4,6 +4,11 @@ #include "ProjectileRocket.h" #include "Kismet/GameplayStatics.h" +#include "NiagaraFunctionLibrary.h" +#include "NiagaraComponent.h" +#include "Components/AudioComponent.h" +#include "Components/BoxComponent.h" +#include "Sound/SoundCue.h" AProjectileRocket::AProjectileRocket() { @@ -12,10 +17,59 @@ AProjectileRocket::AProjectileRocket() RocketMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision); } +void AProjectileRocket::Destroyed() +{ +} + +void AProjectileRocket::BeginPlay() +{ + Super::BeginPlay(); + + if (!HasAuthority()) + { + CollisionBox->OnComponentHit.AddDynamic(this, &AProjectileRocket::OnHit); + } + + if (TrailSystem) + { + TrailSystemComponent = UNiagaraFunctionLibrary::SpawnSystemAttached( + TrailSystem, + GetRootComponent(), + FName(), + GetActorLocation(), + GetActorRotation(), + EAttachLocation::KeepWorldPosition, + false + ); + } + if (ProjectileLoop && LoopingSoundAttenuation) + { + ProjectileLoopComponent = UGameplayStatics::SpawnSoundAttached( + ProjectileLoop, + GetRootComponent(), + FName(), + GetActorLocation(), + EAttachLocation::KeepWorldPosition, + false, + 1.f, + 1.f, + 0.f, + LoopingSoundAttenuation, + static_cast(nullptr), + false + ); + } +} + +void AProjectileRocket::DestroyTimerFinished() +{ + Destroy(); +} + void AProjectileRocket::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) { APawn* FiringPawn = GetInstigator(); - if (FiringPawn) + if (FiringPawn && HasAuthority()) { AController* FiringController = FiringPawn->GetController(); if (FiringController) @@ -35,5 +89,36 @@ void AProjectileRocket::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, ); } } - Super::OnHit(HitComp, OtherActor, OtherComp, NormalImpulse, Hit); + + GetWorldTimerManager().SetTimer( + DestroyTimer, + this, + &AProjectileRocket::DestroyTimerFinished, + DestroyTime + ); + + if (ImpactParticles) + { + UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ImpactParticles, GetActorTransform()); + } + if (ImpactSound) + { + UGameplayStatics::PlaySoundAtLocation(this, ImpactSound, GetActorLocation()); + } + if (RocketMesh) + { + RocketMesh->SetVisibility(false); + } + if (CollisionBox) + { + CollisionBox->SetCollisionEnabled(ECollisionEnabled::NoCollision); + } + if (TrailSystemComponent && TrailSystemComponent->GetSystemInstanceController().IsValid()) + { + TrailSystemComponent->GetSystemInstanceController()->Deactivate(); + } + if (ProjectileLoopComponent && ProjectileLoopComponent->IsPlaying()) + { + ProjectileLoopComponent->Stop(); + } } diff --git a/Source/Blaster/Weapon/ProjectileRocket.h b/Source/Blaster/Weapon/ProjectileRocket.h index 08701da..122d015 100644 --- a/Source/Blaster/Weapon/ProjectileRocket.h +++ b/Source/Blaster/Weapon/ProjectileRocket.h @@ -15,13 +15,34 @@ class BLASTER_API AProjectileRocket : public AProjectile GENERATED_BODY() public: AProjectileRocket(); - + virtual void Destroyed() override; protected: virtual void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) override; + virtual void BeginPlay() override; + void DestroyTimerFinished(); + + UPROPERTY(EditAnywhere) + class UNiagaraSystem* TrailSystem; + UPROPERTY() + class UNiagaraComponent* TrailSystemComponent; + + UPROPERTY(EditAnywhere) + USoundCue* ProjectileLoop; + + UPROPERTY() + UAudioComponent* ProjectileLoopComponent; + + UPROPERTY(EditAnywhere) + USoundAttenuation* LoopingSoundAttenuation; private: UPROPERTY(VisibleAnywhere) UStaticMeshComponent* RocketMesh; + + FTimerHandle DestroyTimer; + + UPROPERTY(EditAnywhere) + float DestroyTime = 3.f; };