In a course I’m taking, I’m learning about debugging with line traces and sweeping. In this example, we’re using DrawDebugSphere
. Here’s the code for reference:
void UGrabberComponent::Grab()
{
const FVector Start = GetComponentLocation();
const FVector End = Start + GetForwardVector() * MaxGrabDistance;
DrawDebugLine(GetWorld(), Start, End, FColor::Red, false, 5.0f);
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();
if (HitActor)
{
DrawDebugSphere(GetWorld(), HitResult.Location, 10, 10, FColor::Red, false, 5);
DrawDebugSphere(GetWorld(), HitResult.ImpactPoint, 10, 10, FColor::Blue, false, 5);
}
}
}
I understand the concept of a HitResult.ImpactPoint
; it seems pretty straightforward. However, I’m puzzled about why HitResult.Location
is positioned about 1 meter away from the hit actor (see screenshot 1).
The explanation in the docs isn’t very clear. They describe Location as: “The location in world space where the moving shape would end up against the impacted object, if there is a hit.”
I have a couple of questions:
- Why is the
HitResult.Location
(red) sphere in my example located about 1 meter from the hit actor? The collision mesh seems simple enough (refer to screenshot 2). - Why do I see
HitResult.ImpactPoint
(the blue sphere above the hit mesh in screenshot 3) even when the trace is significantly above the mesh? I have the same question regarding the red sphere, which representsHitResult.Location
.