PlayerCameraManager->GetCameraLocation vs GetPlayerViewPoint?

Rather than PlayerCameraManager->GetCameraLocation, can we not also use the good old CameraRotation.Vector() from GetPlayerViewPoint(​CameraLocation, CameraRotation) ?

I would say splitting up the function into GetLookDirection and GetLookVectorHitLocation is a little excessive, you even end up discarding the CameraLocation just to get it again, so it makes more sense to me to cut those two functions entirely so

FVector LookDirection;
if (GetLookDirection(ScreenLocation, LookDirection))
{
    // Line-trace along that LookDirection, and see what we hit (up to max range)
    GetLookVectorHitLocation(LookDirection, HitLocation);
}

would become

FVector LookDirection;
FVector CameraLocation; 
if (DeprojectScreenPositionToWorld(ScreenLocation.X,ScreenLocation.Y, CameraLocation, LookDirection))
{
    // Line-trace along that LookDirection, and see what we hit (up to max range)
    FHitResult HitResult;
    auto EndLocation = CameraLocation + (LookDirection * LineTraceRange);
    if (GetWorld()->LineTraceSingleByChannel(HitResult, CameraLocation, EndLocation, ECollisionChannel::ECC_Visibility))
    {
        HitLocation = HitResult.Location;
        return true;
    }
    HitLocation = FVector(0);
    return false; // Line trace didn't succeed
}
return false

Also, looking at @ben’s code for this lecture his function GetSightRayHitLocation will never return false.

Edit: Just looked at the end state and it does indeed return proper values, so I guess will come in the next or a future lecture.

3 Likes

Privacy & Terms