# Simple Raytrace distance = 0

**URL:** <https://forums.unrealengine.com/t/simple-raytrace-distance-0/444965>\
**Category:** Rendering\
**Tags:** Raycast, hit-detection, hit-result, unreal-engine, hit-event, CPP, question\
**Created:** [March 9, 2019, 9:39pm UTC](https://forums.unrealengine.com/t/simple-raytrace-distance-0/444965 "2019-03-09T21:39:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Resupply8672](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Resupply8672](https://forums.unrealengine.com/u/Resupply8672)\
**Post date:** [March 9, 2019, 9:39pm UTC](https://forums.unrealengine.com/t/simple-raytrace-distance-0/444965/1 "2019-03-09T21:39:55Z")

</div>

I’ve written a function which raytraces directly downwards from the VR camera (to detect if the player is currently ducking), but the distance is returning 0 in the log.

I’ve avoided self- collision with AddIgnoredActor(this), and I can’t detect what the raytrace is hitting.

Attempting to print out the name of the actor/component that gets hit in the log results in a crash (most likely because nullptr).

```
	// Ray Casting downwards from the HMD
	FHitResult* hitResult = new FHitResult();
	FVector hmdLocation = CameraComp->GetComponentLocation();
	FVector endTrace = hmdLocation + (FVector(0.0f, 0.0f, -90.0f) * 50.0f);
	FCollisionQueryParams traceHmdDistanceParams = FCollisionQueryParams(FName("HMD Duck Raycast"), true, this);
	traceHmdDistanceParams.AddIgnoredActor(this); // Ignore ourselves in the collision detection
	GetWorld()->LineTraceSingleByChannel(*hitResult, hmdLocation, endTrace, ECC_WorldStatic, traceHmdDistanceParams); // Start Raycast
	
	// Show HMD raycasts in the world
	DrawDebugLine(GetWorld(), hmdLocation, endTrace, FColor::Red, true);

	if (hitResult->Distance <= duckingHeight)
	{
		UE_LOG(LogTemp, Warning, TEXT("Player HIT actor / Distance to ground: %f"), hitResult->Distance);
	}

```

Bit stuck here, any help appreciated.

---

<div class="post-metadata">

**Author:** ![Resupply8672](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Resupply8672](https://forums.unrealengine.com/u/Resupply8672)\
**Post date:** [March 10, 2019, 1:06am UTC](https://forums.unrealengine.com/t/simple-raytrace-distance-0/444965/2 "2019-03-10T01:06:06Z")

</div>

Fixed. Multiple issues, the floor Static Mesh didn’t have collision so the trace wasn’t hitting anything. I’ve simplified the function also: [https://i.imgur.com/H0knBxY.png](https://i.imgur.com/H0knBxY.png)
