How do I check if an object is aimed at?

Hello guys,

I will try to be specific here. What I currently want is a way to check if the player stands on a box trigger and aims at / looks at an object. I have a book that is placed on a table. When the player is near it and looks at it and presses the right mouse button, the event should print a string and destroy itself, or set a value. That’s the idea. An event should occur.

What is the best way to get around doing this?

Thanks!

If you’re using the first person view, you could get a line trace from the camera to a few hundreds or thousand units in front of you as per your need. If the trace hits anything on the path, you can get the hit result and check if it’s your book actor. You could call this functionality only when your character is within the trigger you mentioned. Here’s a screenshot to help you:

From the break hit result shown above, you can get the hit actor and cast it your book class to see the line trace hit your book. Hope that helps.

Yes, in fact you can use the same noes that are shown above. Basically what it’s doing is tracing out a line from your camera to a certain distance in the view direction. The first object that gets hit by the trace is then obtained as the hit actor in the break hit result node. You can then cast that actor into whatever type of class you want.

Is it hard to set up? Im fairly new to UE4 and im not sure what I need really. Haven’t learned all the nodes yet.