I have door open BP scipting, via timeline node. and of course I use trigger box to detect when is player at door. When player come to door and press E - door open. Simply, like tutorials from you tube.
But I want that door will only open when:
1.) Player is on trigger box.
2.) When player look at door.
How to do that?
In player blueprint - I made simply line trace by chanell, to print on screen object name that I am looking. And this is working great. When I look at door - it print “Door1.xxx.xxxxx” etc. When I look at landscape, it prints “LandscapeMain.1.xxxx”…
But how to tell to door - that every tick door must compare if player is looking at door? Is there some node that automaticaly check if player is looking at some object, or I must tu make fName varibale to save object name, and then check every single frame what is player looking?
Make a variable that stores the Hit Actor Reference of the Trace.
Then create a new event with your input Key (Lets say “E”)
Event input “E” Pressed -> get Hit Actor Reference Variable -> is valid -> true -> cast to Interactable Object (or your Door Class) -> Cast success -> Call “Open / Close” Function / Event of the Door Actor given by the cast
If you you want add the trigger:
Go into the door blueprint, select the box collision of the trigger, create a new Event On Begin Overlap
Get the Actor of the begin overlap event, cast it to player, set a variable bool (lets say isPlayerInTrigger) to true.
Make a branch check for that variable in your Open / Close door function.
None of em.
If you click on change variable type, you can type in stuff in there.
You’ll type in the name of the door blueprint name, it should show up in the list.
If you move over the List entry of Door, you should get 3 types to chose.
You take the first, the blue one, named Reference.
That means, you can access this door actor from this variable (if its set. That’s why you should check for “is valid” on the “E” Key event) - ( it’s “pointing” to the door actor in your world while set)
Get Doorvariable -> Set visible
Get Doorvariable -> Destroy actor
The Trace Line will give you a “Hit Actor” (or Other Actor, something like that.) as a result. That’s a “pointer” (like above) to the object in your world.
You store that pointer in your variable which i was talking about, so you have access to the door actor through it.
I have one crazy idea how to do this.
Place box collision to camera, values like 1x1x100. Start at camera and finish on point where you are looking (this will be done when is that box attached to camera).
If you overlap area where you want to open doors, activate that camera box collision and check begin/end overlap… and based on overlaps, drive some func in tick (door rotation probably?)
You can get what you want by sending the LineTrace within your ‘E’ input event.
Anyway, your solution isn’t very beautiful in my opinion. I wouldn’t place user input events in the door blueprint. Similar to what KrautPotato posted I suggest the following. I quickly created this by modifying blueprints of mine, so keep your LineTrace start and end, the logic behind your timeline, replace BP_PlayerCharacter by FirstPersonCharacter and BP_Door1 by MainDoorRight etc.
These nodes should be in your FirstPersonCharacter Blueprint:
These nodes should be in your MainDoorRight Blueprint:
Btw are you sure you need the CollisionBox around the door to check if the player overlaps? In most cases you’re fine if you choose the float you’re multiplying your ActorForwardVector with wisely.
At first make sure you created the custom event “Open” in your FirstPersonCharacter Blueprint and you compiled that Blueprint.
Afterwards in your FirstPersonCharacter Blueprint, the cast in your example should be a “Cast To MainDoorRight”. To find the “Open” event, you need to click and drag the “As MainDoorRight” output pin anywhere in your EventGraph and search in the resulting context menu for the “Open” event. Alternatively you can just rightclick the EventGraph, uncheck context sensitive and search for the “Open” event here. Make sure you use the one of your MainDoorRight, there are multiple ones here.
Generally the easiest way would be to let all doors inherit from one Master door class. In this class you implement your Open function. As long as all of your doors open by rotating one mesh this will be fine. The mesh that is rotated obviously needs to exist in the Master door class. You can change it then in each of its child classes. Now you only need to cast the HitActor in your FirstPersonCharacter to this Master door class and call Open on it. This should work for all of your doors. If you have doors that open differently (e.g. sliding doors) you have to override the event Open in those classes.
So a nice way to do this is to create a variable of type HandLamp01_Blueprint Reference in your switch1 Blueprint. Make this variable Editable. Now you can plug this variable directly in the TurnLightonSwitch node at the end of your SwitchPress node.
In your level editor now click on one instance of your switch1. Because your newly created variable is editable you should now see this variable in the details panel. Set this variable to the instance of your HandLamp01_Blueprint you want to switch on with this exact switch1 you have currently selected. Your switch should now turn on the correct light you want it to. Of course you need to do this for each of your switch1 instance you have in your level.
Generally I guess you will have more than only one lamp Blueprint. Therefore I would suggest you to make the same I told you about the doors. Create a Master Lamp Blueprint each of your lamp inherits from, implement the TurnLightOnSwitch function here and make the lamp reference in your switch1 Blueprint be of the type of your Master lamp Blueprint. Now you should be able to turn each lamp on with this switch1.
I tried your way, and it dont works. But then I convert that variable to array, and it works now. So after SetRelativeRotation, I called a ForEachLoop node, connect that node to TurnLighonSwitch, and variable to array and array element (that I saw on you tube).
And after that, I just picked in details on my switch - which lamp I want.
And just need to replace position of event TurnLight, before Timeline, because I have light show
But now is little stupid that all light is instanced of MasterBPLight, and all lights automatic is ON when I start game.
Now I must create another MasterBPLight which will be OFF when I start game.