131 - Spawning Rocket Trails
This commit is contained in:
parent
34afe73a63
commit
b247adc32d
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -8,7 +8,7 @@ public class Blaster : ModuleRules
|
||||||
{
|
{
|
||||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
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[] { });
|
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,17 @@ protected:
|
||||||
UPROPERTY(EditAnywhere)
|
UPROPERTY(EditAnywhere)
|
||||||
float Damage = 20.f;
|
float Damage = 20.f;
|
||||||
|
|
||||||
private:
|
UPROPERTY(EditAnywhere)
|
||||||
|
class UParticleSystem* ImpactParticles;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
class USoundCue* ImpactSound;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere)
|
UPROPERTY(EditAnywhere)
|
||||||
class UBoxComponent* CollisionBox;
|
class UBoxComponent* CollisionBox;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
class UProjectileMovementComponent* ProjectileMovementComponent;
|
class UProjectileMovementComponent* ProjectileMovementComponent;
|
||||||
|
|
||||||
|
@ -39,10 +45,4 @@ private:
|
||||||
|
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
class UParticleSystemComponent* TracerComponent;
|
class UParticleSystemComponent* TracerComponent;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere)
|
|
||||||
UParticleSystem* ImpactParticles;
|
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere)
|
|
||||||
class USoundCue* ImpactSound;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,6 +4,11 @@
|
||||||
#include "ProjectileRocket.h"
|
#include "ProjectileRocket.h"
|
||||||
|
|
||||||
#include "Kismet/GameplayStatics.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()
|
AProjectileRocket::AProjectileRocket()
|
||||||
{
|
{
|
||||||
|
@ -12,10 +17,59 @@ AProjectileRocket::AProjectileRocket()
|
||||||
RocketMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
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<USoundConcurrency*>(nullptr),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AProjectileRocket::DestroyTimerFinished()
|
||||||
|
{
|
||||||
|
Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
void AProjectileRocket::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
|
void AProjectileRocket::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
|
||||||
{
|
{
|
||||||
APawn* FiringPawn = GetInstigator();
|
APawn* FiringPawn = GetInstigator();
|
||||||
if (FiringPawn)
|
if (FiringPawn && HasAuthority())
|
||||||
{
|
{
|
||||||
AController* FiringController = FiringPawn->GetController();
|
AController* FiringController = FiringPawn->GetController();
|
||||||
if (FiringController)
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,34 @@ class BLASTER_API AProjectileRocket : public AProjectile
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
public:
|
public:
|
||||||
AProjectileRocket();
|
AProjectileRocket();
|
||||||
|
virtual void Destroyed() override;
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) override;
|
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:
|
private:
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
UStaticMeshComponent* RocketMesh;
|
UStaticMeshComponent* RocketMesh;
|
||||||
|
|
||||||
|
FTimerHandle DestroyTimer;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
float DestroyTime = 3.f;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue