Trouble in LineTraceSingleByChannel method to get HitLocation

Hi, I’ve run into an issue where it always logs Something went wrong.it cannot do line trace and also that’s why I can’t call the AimAt method because it always returns false.

bool AMyPlayerController_Class::getHitLocation(FVector worldDirection, FVector &hitlocation)  const {
	FHitResult hitResult;
	auto cameraLocation = PlayerCameraManager->GetCameraLocation();
	auto endLocation = cameraLocation + (worldDirection*LineTraceRange);
	if (GetWorld()->LineTraceSingleByChannel(hitResult,cameraLocation,endLocation,ECollisionChannel::ECC_Visibility)){
		hitlocation = hitResult.Location;
		return true;
	}
	DrawDebugLine(GetWorld(),
		cameraLocation, endLocation,
		FColor(255, 0, 0), 0.f, 0.f, 0.F, 3.F);
	hitlocation = FVector(0);
	UE_LOG(LogTemp, Warning, TEXT("Something went wrong"))
	return false;
}

Note: LineTraceRange = 100000;

And what are you getting for the debug line?

I m getting straight line originating from camera .and its not changing with camera rotation and movement .

Could you send your project? File > Package Project > Zip Up Project and then upload that somewhere like Google Drive.

Sorry for the very late reply buts here is the link

Battle Tank

please help me find out whats wrong with it

AMyPlayerController_Class::getLookDirection(FVector2D screenCrosshairLocation, FVector worldLocation, FVector worldDirection)

worldLocation and worldDirection are supposed to be output parameters. You’re passing them by value which means the variables you pass in aren’t going to be modified at all, they need to be passed by reference.

Okay thanks for the solution ,I will keep that in my mind next time .

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