#include "MProjectile.h" #include "NiagaraComponent.h" #include "NiagaraFunctionLibrary.h" #include "Components/CapsuleComponent.h" #include "GameFramework/ProjectileMovementComponent.h" AMProjectile::AMProjectile() { PrimaryActorTick.bCanEverTick = true; CapsuleComponent = CreateDefaultSubobject(TEXT("CapsuleComponent")); RootComponent = CapsuleComponent; MeshComponent = CreateDefaultSubobject(TEXT("MeshComponent")); MeshComponent->SetupAttachment(RootComponent); MeshComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision); ParticleSystem = CreateDefaultSubobject(TEXT("ParticleSystem")); ParticleSystem->SetupAttachment(RootComponent); ProjectileComponent = CreateDefaultSubobject(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(); } }