Third Person Item Hover Selection

Hello,
i got a 3rd person camera view with a crosshair in the middle of the screen.
How can i detect if my crosshair is over an actor / item?

I guess with a vector from the viewport?

Thanks for help!

e/ like this

You will have to do a line trace. There are multiple versions depending on what you need. A single line trace (which will stop once it hit something and only return that) and a multi line trace (which will return everything it hit even if it was behind another actor / object it hit).

They will provide a hit result which you then can break to get the actor it hit and do some checks which one it is or pass down an interface event so in case they implement this interface that actor can do something (light up, be collected… something like that).

The trace will take a couple of arguments but the most important one is “Start” and “Target”. Into start you have to plug in the location of your camera (“Get Camera” -> “Get Actor Location”).

Into target you have to put the point in front of you. So you will need to get the “Get Actor Forward Vector” multiply that by the distance it should trace (if you want it to hit pretty much everything just use something like 2k) and add the result on top of your actor location.

I hope this can at least get you started :wink:

Cheers

It’s working, thanks! :slight_smile: