Below is the basic code I’m using to implement a hitscan weapon using a line trace. Pretty standard process. It works fine, except for the Niagara System when I’m setting the BeamEnd equal to the FHitResult.ImpactPoint of a blocking hit. Then it fires the beam in a different direction than the impact point. This exact same code works fine for setting the endpoint of a cascade particle system. In the Niagara System I have the BeamEnd value set to an Vector named TraceEnd, which is the value I’m setting in the code. I’m really not sure where I’m going wrong. Any help would be greatly appreciated.
const USkeletalMeshSocket* MuzzleSocket = GetWeaponMesh()->GetSocketByName(“Muzzle”);
if (MuzzleSocket)
{
FTransform SocketTransform = MuzzleSocket->GetSocketTransform(GetWeaponMesh());
FVector LineTraceStart = SocketTransform.GetLocation();
FVector LineTraceEnd = LineTraceStart + (HitTarget - LineTraceStart) * 1.25f;
FHitResult LineTraceHit;
UWorld* World = GetWorld();
//DrawDebugLine(GetWorld(),LineTraceStart,HitTarget, FColor::Red, false, 3.0f, 0, 1.0f);
if (World)
{
World->LineTraceSingleByChannel(LineTraceHit, LineTraceStart, LineTraceEnd, ECollisionChannel::ECC_Visibility);
TracerEndPoint = LineTraceEnd;
if (LineTraceHit.bBlockingHit)
{
TracerEndPoint = LineTraceHit.ImpactPoint;
//DrawDebugLine(GetWorld(), LineTraceStart, TracerEndPoint, FColor::Blue, false, 3.0f, 0, 1.0f);
WeaponFireHitActor = LineTraceHit.GetActor();
if (WeaponFireHitActor && HasAuthority() && InstigatorController)
{
float WeaponActualDamage = WeaponDamage;
if (SurfaceTypeImpacted == SURFACE_FLESHVULNERABLE)
{
WeaponActualDamage *= WeaponHeadShotMultiplier;
}
UGameplayStatics::ApplyDamage(
WeaponFireHitActor,
WeaponActualDamage,
InstigatorController,
this,
UDamageType::StaticClass()
);
}
if (ImpactParticles_Default)
{
UNiagaraFunctionLibrary::SpawnSystemAtLocation(GetWorld(), ImpactParticles_Default, LineTraceHit.ImpactPoint, LineTraceHit.ImpactPoint.Rotation());
}
}
if (ProjectileTracerBeamParticles)
{
UNiagaraComponent* ProjectileBeam = UNiagaraFunctionLibrary::SpawnSystemAtLocation(GetWorld(), ProjectileTracerBeamParticles, LineTraceStart);
if (ProjectileBeam)
{
ProjectileBeam->SetVectorParameter(FName("TraceEnd"), TracerEndPoint);
}
}
}
}
}
}
}