Created
June 24, 2016 08:16
-
-
Save embiem/d110bc0383c191aae39742b5fe80aa72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool GetSightRayHitLocation(FVector& HitLocation) const | |
{ | |
// Find crosshair position in pixel coordinates | |
int32 ViewportSizeX, ViewportSizeY; | |
GetViewportSize(ViewportSizeX, ViewportSizeY); | |
FVector2D ScreenLocation = FVector2D(ViewportSizeX * CrossHairXLocation, ViewportSizeY * CrossHairYLocation); | |
// "De-project" the screen position of the crosshair to a world direction | |
FVector LookDirection, LookStartLocation; | |
if (DeprojectScreenPositionToWorld(ScreenLocation.X, ScreenLocation.Y, LookStartLocation, LookDirection)) | |
{ | |
// Line-trace along that look direction, and see what we hit | |
FHitResult HitResult; | |
if (GetWorld()->LineTraceSingleByChannel( | |
HitResult, | |
LookStartLocation, | |
(LookStartLocation + LookDirection * LineTraceRange), | |
ECollisionChannel::ECC_Visibility)) | |
{ | |
HitLocation = HitResult.Location; | |
return true; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
UE docs: https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Engine/UWorld/LineTraceSingleByChannel/index.html