Tried for a cleaner method

The way I wrote it, when my siege weapon aims towards the sky, it returns false, rather than 0,0,0. It uses fewer lines of code and is easier to read (at least for me). This was an exceptionally challenging one though.

Also, I put my UE_LOG in the method, rather than calling it all the way from the “GetSightRayHitLocation” method.

Does anyone see a problem with doing it this way? I imagine it will prohibit the player from shooting the sky, but that might be a nice feature anyway.

bool ASiegePlayerController::GetLookHitVectorLocation(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))
	{
		HitResult.Location;
		UE_LOG(LogTemp, Warning, TEXT("2d vector drawing to 3d point at; %s"), *HitResult.ToString())
		return true;
	}
	return false;//line trace didn't succeed
}

Privacy & Terms