How to enable/disable input using raycast

This is pretty simple…

  1. Get the camera position / actor position
  2. Get the camera orientation, then convert that into a look vector.
  3. Place the look vector at the camera eye position
  4. Scale the look vector by the distance you want to search for objects
  5. Apply a “Line Trace by Channel” node, with the eye position and look vector as end points
  6. Grab the “Hit Actor” from the hit result
  7. Cast the hit actor to the light switch blueprint. If the hit actor is a light switch, the cast will succeed. Then, you can activate a bool flag within the player character which enables the “F” input button.
  8. When the player activates their input button, you should send a message to the ‘looked at’ actor and tell it to toggle itself. I recommend blueprint interface messages so that you can have multiple switch types. See the content examples for an example of this.

How can I enable input when a ray hits an object(in my case a lamp) so if I press “F” I can turn the light ON/OFF and disable the input when the ray is not hitting the object so if I’m away and I press “F” I cant turn the lights ON/OFF.

with a helpful message that says “press F” when the ray hits that certain object.

thanks for the response, thats actually where I am right now. I’m goin put my graph so you can see :slight_smile:

You should create a variable for the currently selected object. If your line trace succeeds and hits a valid object type, then you set the currently selected object to that object. If the line trace hits a non-usable object, then you set your currently selected object to “null”. When you go to interact with the currently selected object, put a “IsValid” macro node before trying to use it.

ok so heres my graphs.
INTERFACE

FIRSTPERSON LINE TRACE

and heres where I’m having some problem,. so I can enable input but I dont know how to disable it when the ray is not hitting the object. So once the ray hits the object, it stays enable all the time and I can toggle the light even if I’m away.

if I can just disable it when the ray is not hitting the object.

wow you really are knowledgeable about blueprints and I’m not. I’m really sorry I’m a newbie. you lost me with that, I think I need to learn a lot first before to get that working huh? :frowning:

but thanks for the reply :wink:

Ive been tweaking with the graphs still cant make it work. can you give me an example graph.

Yeah, here is a series of screen shots from my ‘target locking’ system which uses the line traces and target selection, similar to what you’re trying to do. This should help you get on the right track!

If you want to see the complete blueprint, you can stitch these images together in your favorite image editor. I took screenshots from left to right.

I think this is actually much simpler

What I did is I created a new interface for the toggling.
so basically the interface to show the helpful message is another interface.

less nodes but same function. well as of now I can work with this one.