FVector Start = GetComponentLocation();
FVector End = Start + GetForwardVector() * MaxGrabDistance;
DrawDebugLine(GetWorld(), Start, End, FColor::Red);
FCollisionShape Sphere = FCollisionShape::MakeSphere(GrabRadius);
FHitResult HitResult;
bool HasHit = GetWorld()->SweepSingleByChannel(HitResult,
Start,
End,
FQuat::Identity,
ECC_GameTraceChannel2,
Sphere);
if (HasHit)
{
AActor* HitActor = HitResult.GetActor();
UE_LOG(LogTemp, Display, TEXT("HitActor : %s"), *HitActor->GetActorNameOrLabel());
DrawDebugSphere(GetWorld(), HitResult.Location, 10, 10, FColor::Red, false, 5);
DrawDebugSphere(GetWorld(), HitResult.ImpactPoint, 10, 10, FColor::Blue, false, 5);
}
Hit結果からはLocationとImpactPointを取得できる
今回の場合は
SweepではなくLineTraceByChannelの場合はImpactPoint==Locationになるので注意