Camera distance to character in Meters

Hi Hivemind,

Im trying to create a tool for a virtual camera that measures the distance to a character/object/static mesh and hights ground and outputs the distance in Meters, and prints the Name of the character (object) on a UI/HUD. In Unreal Engine 5.1

Im really new to blueprinting so im trying to find a tutorial or help in getting started.

I was thinking of casting a ray from the camera and getting the distance there, but Im getting stuck on the basics.

I need a bit of help finding the right tutorial or link to something that could help me.

Thanks!

Ok here are the basic…
suppose we have a camera and some object like a cube:

You want to linetrace from the camera towards its viewing direction and evaluate if it hits some object. You must do this for the linetrace:

this is the results:

you can see that is hitting because at the end there is a red rectangle.

in the blueprint:

IMPORTANT: Note trace channel is set to visibility:

image

the box is set to default:

image

but you can cherry pick what do you want to be used in the tracing if you select custom…all set to block will generate hits in their channel:

image

you can also make a custom Trace Channel in settings like this:

but remember to set that channel in your objects as BLOCK and also in the bleuprint node:

image

image

Hope it helps

Cheers!
Dany

2 Likes

To expand on the above:

  • create a widget representing the display, but make it better than this:

  • expose any fields you’d wish to update:

image

  • have the widget feed the incoming data to its fields via a Custom Event:

This is also the place where I’d parse / decorate the data. 100uus = 100cm, so divide by that much to get meters.

  • in the pawn with the camera add a widget component that lives in Absolute Space but displays in Screen Space:

  • script in the pawn:

  • the result:


See if you get this working first. It measures the distance from the camera to the object we’re looking at. You’d then refactor it to work with things other than the pawn we’re looking through. Hard to advise without knowing more.

2 Likes

Holy Handgrenade!

I did not expect this so soon and this detailed! Im going to go through it all! you a re the best! Thank you so much for this!

Gotta love this community!

All the best!

2 Likes