Get the polar coordinates of the point where the player is looking at.

Hi!

I’m using Unreal 5.4.2 on a game with C++ and Blueprint.

Is there a way to get the polar coordinates where the player is looking at?

I’m not sure, but I could use Deproject Screen to World | Unreal Engine Documentation

imagen

Or use the camera elevation to get the phi somehow unknown to me, but I don’t know how to get the theta.

By the way, I have tried this and it doesn’t work because I’m not hitting anything:

Return value is false and Out Hit Location is (0.0f, 0.0f, 0.0f).

Thanks!

in your trace, it seems the camera manager is just a manager, that is likely placed at (0,0,0) or god knows where. You need the actual camera object transform as the source of ForwardVector. The rest seems fine. Can also toggle DrawDebug enum to see where the trace realy going

As for polar coordinates: you getting the cortesian point via this trace and then converting it to system you need. Idk if there is a default function for this, but writing conversion manually isn’t that hard. Accoding to wiki it’s just the
изображение

upd: if you meant the Spherical coordinates then it’s also not that much harder:
изображение

It’s exactly where the player controller’s current view target is in WS, and the direction matches, too - it’s a universal way of obtaining data regardless of which camera we’re using. It is, essentially, current camera.

None of it matters here, though since we’re using world origin 0,0,0 as trace start - so we’re definitely not tracing from the right place unless the player is, indeed, the very centre of the world.


@ViaCognita Not sure what output you’re expecting, do you even need to trace? Perhaps you could clarify what this is for? If you want a universal heading, you can (and/or convert it to degrees):

If you want a world location x units away from the current camera, in the the direction (ignoring Z) it’s facing:


I’ll just add that where the player is and where the camera is may not be the same thing. As in top down view. Stating the obvious :innocent:

Good to know, I’m used to use more convoluted ways of getting current camera. Thanks

we’re using world origin 0,0,0 as trace start

Oops, you right, idk how i missed that

The player will be inside a sphere. The player will be at the origin (0.0f, 0.0f, Z), and the sphere will have a 750.0f radius. By the way, I’m using Z because I don’t know which value to use here.

I need the polar coordinates because I want to compute on which point of the sphere’s surface the player is looking at. Yes, I know that I can use line trace for objects to line a trace to the sphere and know that location, but I’m using this to learn more about Unreal, specially about polar coordinates.

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