My Way Of Doing It

Hi!
I did it quite different. Can I get any comment on whether it is good or not?

bool ATankPlayerController::GetSightRayHitLocation(FVector& OutHitLocation) const
{
	int32 ViewportSizeX, ViewportSizeY;
	FVector LookDirection;
	FVector LookLocation;
	GetViewportSize(ViewportSizeX, ViewportSizeY);
	auto ScreenLocation = FVector2D(ViewportSizeX * CrossHairXLocation, ViewportSizeY*CrossHairYLocation);
	if (GetLookDirection(ScreenLocation,LookDirection,LookLocation))
	{
		FHitResult Hit;
		if (GetLookVectorHitLocation(LookDirection, LookLocation,Hit))
		{
			UE_LOG(LogTemp, Warning, TEXT("%s"),*Hit.GetActor()->GetName())
		}

	}

	return true;
}

bool ATankPlayerController::GetLookDirection(FVector2D ScreenLocation, FVector& LookDirection,FVector& LookLocation) const
{
	return DeprojectScreenPositionToWorld(
		ScreenLocation.X, 
		ScreenLocation.Y, 
		LookLocation, 
		LookDirection);
}

bool ATankPlayerController::GetLookVectorHitLocation(FVector Direction,FVector Location,FHitResult &Hit) const
{
	auto PlayerPawn = GetControlledTank();
	FCollisionQueryParams TraceParametres(FName(TEXT("")), false, GetControlledTank());
	ECollisionChannel Channel = ECC_Visibility;

	return GetWorld()->LineTraceSingleByChannel(
		Hit,
		Location,
		Location + Direction * LineTraceRange,
		Channel,
		TraceParametres
	);
}

Seems just fine to me, works and is clear so what’s not to like?!

Privacy & Terms