Hello, I`m beginner of UE5.
While i`m making my own fps project, i made a target Actor and placed it all over the map.
All target actor is placed on the ground except just one target actor.
This target actor makes problem when its hit by my gun
s linetrace. Other actors works well that i intended.
I checked that this target only makes trouble when it`s on another actor. I have no clue of why this happen.
Ill attach my game
s play video and codes.
void AVIAKWeapon::LineTrace()
{
Super::LineTrace();
if (UWorld* World = GetWorld())
{
APlayerController* PC = UGameplayStatics::GetPlayerController(World, 0);
if (PC)
{
AVICharacter* Character = Cast<AVICharacter>(PC->GetCharacter());
if (Character)
{
// Camera Linetrace
FHitResult HitResult;
FVector TraceStart = Character->GetCamera()->GetComponentLocation() + FVector(0.5f,0.0f,-0.5f);
FVector TraceEnd = Character->GetCamera()->GetForwardVector() * 20000.0f + TraceStart ;
/* Bullet Spread */
if (Character->GetVelocity().Length() > 20.0f)
{
FVector BulletSpreadRandVector(
FMath::RandRange(BulletSpread * -1.0f, BulletSpread)
, FMath::RandRange(BulletSpread * -1.0f, BulletSpread)
, FMath::RandRange(BulletSpread * -1.0f, BulletSpread)
);
TraceEnd = TraceEnd + BulletSpreadRandVector;
}
TArray<AActor*> ActorsToIgnore;
FColor ColorBeforeHit = FColor::Red;
FColor ColorAfterHit = FColor::Green;
float ColorsLifeTime = 5.f;
if (UKismetSystemLibrary::LineTraceSingle(
World,
TraceStart,
TraceEnd,
UEngineTypes::ConvertToTraceType(ECC_Visibility),
false,
ActorsToIgnore,
EDrawDebugTrace::ForDuration,
HitResult,
true,
ColorBeforeHit,
ColorAfterHit,
ColorsLifeTime
))
{
//DF("Hit = %s", HitResult.GetActor()->GetName())
SpawnDecalTracer(Muzzle->GetComponentLocation(), HitResult.ImpactPoint, HitResult.ImpactPoint);
//Play Montage
if (Character->GetbADS())
{
Character->GetFirstPersonMesh()->GetAnimInstance()->Montage_Play(AKADSFireActionMontage, 1.0f);
}
else
{
Character->GetFirstPersonMesh()->GetAnimInstance()->Montage_Play(AKFireActionMontage, 1.0f);;
}
AActor* HitActor = HitResult.GetActor();
if (HitActor)
{
float Damage = 10.0f;
UGameplayStatics::ApplyDamage(HitActor, Damage, Character->GetController(), Character, nullptr);
}
}
}
}
}
}