2022-05-18 12:44:39 +00:00
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
#include "ProjectileRocket.h"
|
|
|
|
|
|
|
|
#include "Kismet/GameplayStatics.h"
|
2022-05-18 17:20:18 +00:00
|
|
|
#include "NiagaraComponent.h"
|
2022-05-19 09:10:41 +00:00
|
|
|
#include "RocketMovementComponent.h"
|
2022-05-18 17:20:18 +00:00
|
|
|
#include "Components/AudioComponent.h"
|
|
|
|
#include "Components/BoxComponent.h"
|
|
|
|
#include "Sound/SoundCue.h"
|
2022-05-18 12:44:39 +00:00
|
|
|
|
|
|
|
AProjectileRocket::AProjectileRocket()
|
|
|
|
{
|
2022-05-20 16:12:50 +00:00
|
|
|
ProjectileMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Rocket Mesh"));
|
|
|
|
ProjectileMesh->SetupAttachment(RootComponent);
|
|
|
|
ProjectileMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
2022-05-19 09:10:41 +00:00
|
|
|
|
|
|
|
RocketMovementComponent = CreateDefaultSubobject<URocketMovementComponent>("RocketMovementComponent");
|
|
|
|
RocketMovementComponent->bRotationFollowsVelocity = true;
|
|
|
|
RocketMovementComponent->SetIsReplicated(true);
|
2022-05-18 12:44:39 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 17:20:18 +00:00
|
|
|
void AProjectileRocket::Destroyed()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void AProjectileRocket::BeginPlay()
|
|
|
|
{
|
|
|
|
Super::BeginPlay();
|
|
|
|
|
|
|
|
if (!HasAuthority())
|
|
|
|
{
|
|
|
|
CollisionBox->OnComponentHit.AddDynamic(this, &AProjectileRocket::OnHit);
|
|
|
|
}
|
|
|
|
|
2022-05-20 16:12:50 +00:00
|
|
|
SpawnTrailSystem();
|
|
|
|
|
2022-05-18 17:20:18 +00:00
|
|
|
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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-18 12:44:39 +00:00
|
|
|
void AProjectileRocket::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
|
|
|
|
{
|
2022-05-19 09:10:41 +00:00
|
|
|
if (OtherActor == GetOwner())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2022-05-20 16:12:50 +00:00
|
|
|
ExplodeDamage();
|
2022-05-18 17:20:18 +00:00
|
|
|
|
2022-05-20 16:12:50 +00:00
|
|
|
StartDestroyTimer();
|
2022-05-18 17:20:18 +00:00
|
|
|
|
|
|
|
if (ImpactParticles)
|
|
|
|
{
|
|
|
|
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ImpactParticles, GetActorTransform());
|
|
|
|
}
|
|
|
|
if (ImpactSound)
|
|
|
|
{
|
|
|
|
UGameplayStatics::PlaySoundAtLocation(this, ImpactSound, GetActorLocation());
|
|
|
|
}
|
2022-05-20 16:12:50 +00:00
|
|
|
if (ProjectileMesh)
|
2022-05-18 17:20:18 +00:00
|
|
|
{
|
2022-05-20 16:12:50 +00:00
|
|
|
ProjectileMesh->SetVisibility(false);
|
2022-05-18 17:20:18 +00:00
|
|
|
}
|
|
|
|
if (CollisionBox)
|
|
|
|
{
|
|
|
|
CollisionBox->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
|
|
|
}
|
|
|
|
if (TrailSystemComponent && TrailSystemComponent->GetSystemInstanceController().IsValid())
|
|
|
|
{
|
|
|
|
TrailSystemComponent->GetSystemInstanceController()->Deactivate();
|
|
|
|
}
|
|
|
|
if (ProjectileLoopComponent && ProjectileLoopComponent->IsPlaying())
|
|
|
|
{
|
|
|
|
ProjectileLoopComponent->Stop();
|
|
|
|
}
|
2022-05-18 12:44:39 +00:00
|
|
|
}
|