UE4【C++】【屏幕空间转世界空间】

AActor* APlayerController::GetActorUnderPoint(const FVector2D& point) const
{
	FVector location, direction;
	DeprojectScreenPositionToWorld(point.X, point.Y, location, direction);

	FCollisionQueryParams TraceParams(FName(TEXT("")), true, this);
	TraceParams.bReturnPhysicalMaterial = false;
	TraceParams.bTraceComplex = false;

	FHitResult hit(ForceInit);
	float endOffset = 500;
	FVector target = location + (direction * endOffset);
	GetWorld()->LineTraceSingleByChannel(hit, location, target, ECC_GameTraceChannel1, TraceParams);
	return hit.GetActor();
}

 

你可能感兴趣的:(UE4)