Problem with LineTraceSingleByChannel on mountain terrain

When I aim my tank at the ground, I see a value that i would expect, but as soon as I aim my crosshairs at a location that has been morphed (mountains and valleys), I get the 0 value that indicates that I am not hitting anything. I’m using 4.15. I’m not sure how to debug this problem.

I’ve added my GetLookVectorHItLocation function implementation in case there’s something that I’m missing there.

bool ATankPlayerController::GetLookVectorHitLocation(FVector lookDirection, FVector &HitLocation) const {
FHitResult hitResult;
auto startLocation = PlayerCameraManager->GetCameraLocation();
auto endLocation = startLocation+(lookDirection*lineTraceRange);
if(GetWorld()->LineTraceSingleByChannel(
        hitResult,
        startLocation,
        endLocation,
        ECollisionChannel::ECC_Visibility
   )){
    HitLocation = hitResult.Location;
    return true;
}
HitLocation = FVector(0);
return false;

}

I suppose your linetrace is too short.

2 Likes

Privacy & Terms