How to press E key, when in box trigger box only, to open door?
Hi is there a way to 'open a door' by 'pressing the E key', which only works 'when the player is within the trigger box' only?
asked Apr 18 '16 at 04:59 AM in Blueprint Scripting
Look at my example. I think it is easy to understand.
answered Apr 18 '16 at 09:20 AM
Don't do this in the LevelBlueprint. The LevelBlueprint should be the last thing to think about, if you do such things.
Do it inside of the Door like this:
Add the OnComponentBeginOverlap and OnComponentEndOverlap of the CollisionBox, which you already added to the door, to your EventGraph by selecting it and scrolling down until you find the green buttons on the right side:
And then do this:
What this does is:
Enable Input for the Door Actor when the Player overlaps (and only the Player).
Disable Input for the Door Actor when the Player stops overlapping (and only the Player).
If Input is enabled, open the Door when pressing E. I only play a sound here, because I don't have a door at hand.
You might need some more logic, for example let the Door open completely before the E Press works again, so the Player can't spam the button. But that's how you Enable Input for a Door (: No LevelBlueprint needed.
NOTE This is a SinglePlayer solution. Won't work in Multiplayer.
answered Apr 18 '16 at 01:00 PM
I'd say you just need to put some check logic in place on the input. Say, set the box trigger to set a boolean on overlap with the player character and put a branch on the input event that checks that boolean.
answered Apr 18 '16 at 07:10 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here