How can I get the location the player is looking?

Hi everyone How can I get the location the player is looking?
I mean like I can get the location where the EXACT center of screen meets the ground or anything that helps in that direction.

1 Like

What sort of player? ( first or third person )

FIrst person character. Sorry i didn’t make it clear in the first post

3GS Game Studio has a neat guide on it, they also provide a ffree Plugin on the Market Place that enables what theyre covering with less additional BP/CPP

Its applicable for first person as well.

This is how I did it in a FPS game (C++ but should be easy to translate to BP if you’re using BP)

Range is just a float for how far I want to do the trace, can be anything you want

const FVector cameraForwardV = playerController->PlayerCameraManager->GetActorForwardVector();
const FVector cameraLocation = playerController->PlayerCameraManager->GetCameraLocation();

FVector traceEnd = cameraLocation + cameraForwardV * Range;
FCollisionQueryParams params = FCollisionQueryParams::DefaultQueryParam;
FHitResult m_calculatedhit;

GetWorld()->LineTraceSingleByChannel(m_calculatedHit, source, traceEnd, ECC_Visibility, params);

The structure of m_calculated hit will have all the info you need:

  • what object was hit
  • where the hit occured
  • etc.

Do a line trace.
Trace start is the actor location.
Trace end is the actor location + (camera forward vector * 10000(or more zero if you need)).
After the line trace node check if it hit something,break the hit results, the hit location in the hit results is where the player is looking at

@baobao4435 has the correct answer

1 Like

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