Enable player input when looking at object
I'm trying to get a player input to work only when player is looking at it. Specifically, allowing the player to open a door only when he is inside the hitbox, and looking at the door.
Here's the blueprint for the door: https://blueprintue.com/blueprint/06smlcfa/
I've looked at tutorials about these line trace nodes, but I cannot for the life of me get them to work. So here, the whole lookAt part of the blueprint is not working. What exactly is wrong here?
asked Oct 22 '18 at 04:53 PM in Blueprint Scripting
The first thing I would try is printing out what you are hitting when a hit result happens, if you are hitting anything at all. Because it sounds like your trace channel isn't setup correctly therefore the raytrace is never colliding with the door.
EDIT: Updated info.
So they way I believe you want this to be set up is if the player is standing next to the door AND looking at it, they can open it.
Here is how I set that up:
I tried setting up a branch and print strings, and sure enough, the trace doesn't work. If I try trace channel visibility, the trace turns green when it passes through anything, and with camera it doesn't turn green for anything.
I don't get it. In my mind, it should be dead simple - if line is hitting this component, set boolean value that enables player input, but it doesn't work like that. I tried with a different blueprint actor with containing just a cube as well, same result.
answered Oct 23 '18 at 12:00 PM
Your LineTraceByChannel is stopping on the first actor hit, regardless of whether it an actor you care about.
You can use MultiLineTraceByChannel, use for a foreach loop on the hit result, break it, and check if any of the the hit actors are your door. If any hit result is your door, then you can set the "lookAt" to true, if not, do nothing.
To achieve the changing of lookAt to false, I would simply set it to false before performing this loop, and then it will only be changed back to true if your door actor was hit.
Hope this helps!
answered Oct 23 '18 at 02:56 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here