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.
Mar 09 '19 at 09:39 PM
in C++ Programming