Know the coordinate towards the camera is looking at

Hi!

I’m using Unreal 5.4.2 in a C++ game.

I would like to know the coordinate towards which the camera is looking at a certain instant. This coordinate is always at 7500 units, because the camera would be at the imaginary centre of a sphere whose radius would be 7500 units. How can I calculate it?

I suppose I can use the vectors Forward, Up and Right, but I don’t know how it would affect if the camera is looking parallel to the ground or if it forms an angle (because it is looking down or up). By the way, the camera will not be at ground level, but at a certain height.

Maybe I could use also LineTrace, but I would need an object at 7.500 units. Maybe an invisible sphere, but I tried to use a sphere with a static mesh and the pawn can’t stay inside.

Thanks!

You can set the sphere to no collision :slight_smile:

You can also do it mathematically, if you control the camera with polar coordinates

image

1 Like

Thanks.

How can I control the camera with polar coordinates?

1 Like

There’s just two angles, Theta and Phi, which basically equate to Yaw and Pitch, or the other way around :slight_smile:

1 Like

OK. I’ll check it. Thanks.

1 Like

It’s very easy, the math page makes it look difficult :slight_smile:

I just took a quick look at some code I have with this, and the two angles need to be in radians :wink:

Then you can just

So that’s me multiplying by the distance, and that final coord is the one you want.

So, to know the (X, Y, Z) coordinate of the point which the camera is looking at, I have to use camera’s Yaw and Pitch, convert to Cartesian coordinate and multiply by 7.500. Is that correct?

1 Like

In radians.

Correct :smiley:

Why in radians?

Because he is using the trigonometric functions which only accepts radians, Sin (Radians) | Unreal Engine Documentation.

There is a version which accepts degrees, Sin (Degrees) | Unreal Engine Documentation.

1 Like