You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.7 KiB
48 lines
1.7 KiB
#include "MProjectile.h"
|
|
|
|
#include "NiagaraComponent.h"
|
|
#include "NiagaraFunctionLibrary.h"
|
|
#include "Components/CapsuleComponent.h"
|
|
#include "GameFramework/ProjectileMovementComponent.h"
|
|
|
|
AMProjectile::AMProjectile()
|
|
{
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
|
|
CapsuleComponent = CreateDefaultSubobject<UCapsuleComponent>(TEXT("CapsuleComponent"));
|
|
RootComponent = CapsuleComponent;
|
|
|
|
MeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComponent"));
|
|
MeshComponent->SetupAttachment(RootComponent);
|
|
MeshComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
|
|
|
ParticleSystem = CreateDefaultSubobject<UNiagaraComponent>(TEXT("ParticleSystem"));
|
|
ParticleSystem->SetupAttachment(RootComponent);
|
|
|
|
ProjectileComponent = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovement"));
|
|
ProjectileComponent->InitialSpeed = 12000.f;
|
|
ProjectileComponent->MaxSpeed = 18000.f;
|
|
ProjectileComponent->ProjectileGravityScale = 0.f;
|
|
}
|
|
|
|
void AMProjectile::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
CapsuleComponent->OnComponentBeginOverlap.AddDynamic(this, &rojectile::HandleBeginOverlap);
|
|
SetLifeSpan(5.f);
|
|
}
|
|
|
|
void AMProjectile::HandleBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
|
{
|
|
AActor* ProjectileOwner = GetOwner();
|
|
if(ProjectileOwner && OtherActor != ProjectileOwner && !ActorClassesToIgnore.Contains(OtherActor->GetClass()))
|
|
{
|
|
if(ImpactEffect)
|
|
{
|
|
UNiagaraFunctionLibrary::SpawnSystemAtLocation(GetWorld(), ImpactEffect, SweepResult.ImpactPoint, SweepResult.ImpactNormal.Rotation());
|
|
}
|
|
Destroy();
|
|
}
|
|
}
|
|
|