How to interact with objects when facing them?

I need help real quick, I wanted to make my item interactable only when looking at it. I know how to make basic interactable objects with boxes, pressing E when overlapping the box to pick it up, stuff like that. But this time I want to only be able to interact with my item when looking directly at it. How do I do this.

I’d suggest… instead of putting the trigger box on the object, put the trigger area as a component on your player character…

make the E event available when you overlap an interactable item…

If you only want to be able to interact with an item when looking directly at it, I might suggest using a line trace rather than the overlapping trigger box. When you press your interact button, fire a line trace from your camera.

The start position will be your camera location, the end location would be the location of the camera, plus the forward vector of the camera multiplied by a float, which would control the interact distance.

After this there are a couple of way to trigger the interaction. The way I would do it would be to use a blueprint interface to fire off whatever interaction I want on the specific item I was looking at that would also implement the interface (i.e. a switch would toggle, a door would open, a box would get picked up, etc.). Using a blueprint interface would mean I wouldn’t need to worry about casting, and if the trace hit something that didn’t implement the interface (like a wall or floor) nothing would happen.

Just a quick note, this approach would work well if you are creating a first person experience. If you were doing a third person game, or top down, then the trigger box on the character approach suggested by aNorthStar might be a better option.

Thanks for all the comments, So I did what NorthStar said, I created a new object called InteractBox, attached it to my player, this new InteractBox attached to my player has a rectangular box, so when an item collides with my InteractBox I can press E to pick the item up. It works pretty well, so thanks everyone!

using traces would work but it also depends on the situation. if you have a cross-hair your good since you can get a specific point to focus on, but if your using a different camera angle or no cross-hair you may want to use a shape-trace instead. by using a shape-trace you dont need to be as precisely focused on the object to interact with. though this method does have a downside in that if you have many small objects close together you may not get the one you want.

I agree with Arceyo and Thompson… but imho the benefit of using a trigger box (instead of a line or a box-shaped trace, actively triggered by player) is that the player can get a passive notification “Press E to Interact” and I “think” a trigger box would be more performance efficient than having a trace on all the time to get the same passive notification.

… but for active instigating pickups, without a notification (maybe pickups have a special particle glow or something)… Arceyo and Thompson’s way is better imho

good news… your welcome! :slight_smile:

…just a thought, regarding performance efficiency, as you know there are a bunch of ways to do it but I think just using a collision box as a component on your Character would be the best setup