Hi! This is my code… I am using version UE4-27
void AProtagonist_Player2::Shoot()
{
FHitResult Hit;
FVector Location;
FRotator Rotation;
GetController()->GetPlayerViewPoint(Location, Rotation);
FVector LineTraceEnd = Location + (Rotation.Vector() * 2000);
FCollisionQueryParams QueryParams;
GetWorld()->LineTraceSingleByChannel(Hit, Location, LineTraceEnd, ECollisionChannel::ECC_Visibility, QueryParams);
//DrawDebugLine(GetWorld(), Location, LineTraceEnd, FColor::Orange, false, 5.f);
AActor* HitActor = Hit.GetActor();
UE_LOG(LogTemp, Warning, TEXT("Hit Actor: %s"), *(HitActor->GetName()));
EnemyActor = Cast<AProtagonist>(Hit.GetActor());
if (EnemyActor != nullptr)
{
EnemyActor->ReduceHealth();
}
UE_LOG(LogTemp, Warning, TEXT("Health: %f"), EnemyActor->Health);
}
As you can see i logged out the HitActor but nothing shows up in the editor…
(BTW this is my first question in here, im sorry about anything that doesn’t match your expectations)