52 lines
1.1 KiB
C++
52 lines
1.1 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "Weapon/LMBulletTracer.h"
|
|
#include "NiagaraComponent.h"
|
|
|
|
|
|
ALMBulletTracer::ALMBulletTracer()
|
|
{
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
|
|
TrailFx = CreateDefaultSubobject<UNiagaraComponent>(TEXT("Tracer FX"));
|
|
RootComponent = TrailFx;
|
|
}
|
|
|
|
void ALMBulletTracer::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
TrailFx->SetVariableFloat("Lifetime", TrailLifeTime);
|
|
}
|
|
|
|
void ALMBulletTracer::Tick(float DeltaTime)
|
|
{
|
|
Super::Tick(DeltaTime);
|
|
}
|
|
|
|
void ALMBulletTracer::Initialize(const FVector& Vector, const FRotator& Direction, USceneComponent* Origin)
|
|
{
|
|
SetActorLocationAndRotation(Origin->GetComponentLocation(), Direction);
|
|
TrailOrigin = Origin;
|
|
|
|
const double Distance = FVector::Distance(Vector, GetActorLocation());
|
|
float const LifeTime = Distance / Speed;
|
|
|
|
OnIntialized(LifeTime);
|
|
}
|
|
|
|
void ALMBulletTracer::DestinationReached()
|
|
{
|
|
GetWorldTimerManager().ClearTimer(TimerHandle);
|
|
TrailFx->Deactivate();
|
|
|
|
OnDestinationReached();
|
|
|
|
GetWorldTimerManager().SetTimer(TimerHandle, [this]
|
|
{
|
|
GetWorldTimerManager().ClearTimer(TimerHandle);
|
|
Destroy();
|
|
}, TrailLifeTime, false);
|
|
}
|
|
|