HitResult.Location weirdness?

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 represents HitResult.Location.



Alright, I realized I wasn’t paying close enough attention to the code, and now I’ve figured out the reason behind it. Essentially, there’s a GrabRadius variable, which determines the radius for the Collision Shape Sphere on this line:

FCollisionShape Sphere = FCollisionShape::MakeSphere(GrabRadius);

If add the collision debug sphere using this line of code:

DrawDebugSphere(GetWorld(), HitResult.ImpactPoint, Sphere.GetSphereRadius(), 25, FColor::Yellow, false, 5);

Everything starts to click into place (refer to the image).

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.