Press Key To Open Door | Interaction System | Unreal Engine 4/5 Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back to the video and in this video I'm going to show you how you can open or close a door when you are near to a lever and when you'll press the key the lever handle will go down and door will open up and if you'll get away from the lever you will be no longer able to open or close the door and after you come back the keyi will be visible and you will be able to open or close the door again and if you want this lever model the link is in the description so you can download it from there so to do this first let's create a blueprint class of AC type I'm going to name this door BP and let's open this up for the tutorial purpose I'm going to use Cube as a door so let's name this door and you can scale this according to your level after scaling let's compile this and place this into the level after placing the door inside your level you can create another another blueprint class of vector type I'm going to name this lever BP now click on the add component button and search for the static mesh let's add one more okay after that we can assign the MH to the mesh components uh just uh select your mesh in the mesh component and use this small Arrow to assign the mesh and now let's make lever handle the child of the lever box and name them respectively so after that let's add a box Collision component and then we can scale this according to our level so we are going to use this box Collision to check if our player is near this lever so that we can show the wiget to it okay now let's change the location a bit after that let's compile and uh place this into the level so we want to show the widget whenever our player will pass through this Collision box so for that I had already created this user widget where we have this button so let's go to the lever blueprint and let's delete these unnecessary events now let's search for event begin play and now here we can search for create widget and now let's uh create the F button UI yeah this here and let's promote this to variable I'm going to name this button widget reference after that let's add it to the viewport okay so after that let's go to the viewport and we want to add a event begin overlap for the box and after that let's grab the reference of the widget and search for set visibility so we want to set the visibility to visible uh whenever we will overlap through this uh trigger box okay now let's add a on component and overlap and now let's copy the set visibility node and connect the execution pin and the parameters and we want to set the UI to be hidden whenever the our player will leave the trigger box okay so after that let's compile and let's play but we already have this UI on the screen we only want it when our player will overlap through this trigger box so to fix this let's go to our UI then click on class default and in the visibility section you have to choose hidden so it will be hidden by default so let's compile and test this again now as you can see we don't have any UI on the screen by default it only appears when we overlap through this trigger box so now we want to open this door so to do this let's go to our project settings under the edit tab now let's go to the input section and let's add a action mapping I'm going to name this open door and now let's select the F key here it is so you can select any of the key you wanted okay so uh now let's go to our character blueprint okay so here uh we want to call this action mapping Open Door in our event graph of the character blueprint so let's call this open door so when we press it uh we want to get actor of class let's connect the execution pin so we want to get our lever blueprint so let's get it and after that we want to call any custom event or a function so that we can open that door so for that let's go to our L blueprint and here uh we want to create a custom event so let's create it and I'm going to name this open door okay uh now uh what we want to do is we want a branch and we want to check a condition the condition is for that let's get our uh widget reference here we are getting our uh button UI widget reference so let's uh check if it is visible so let's search for is visible node and let's connect the conditions before that let's go to our door blueprint so what we want to do we want to move it in the uh up and down Direction so for that uh first we need the reference to the door blueprint so let's search for get uh actor of class and let's let's search for door blueprint and now let's promote these two variables so that we can use it down below okay so now let's uh grab the reference now from here we can get the door yeah here so let's get the door after that we can set its uh relative location yeah there you go now let's connect the execution pin and we want to change the location of the door in z-axis so let me show you uh if I'll move it up and down you can see the z-axis is also changing that means we need to change it in the z-axis so let's go to our L blueprint here let's change it to uh 410 so now uh what we want to do we want to Let's compile first yeah so uh we want to call this custom event in our third person blueprint so let's go there so as we click the F key from this reference we can actually call that Open Door custom event so when we will press the F key we are calling this event and this event is uh actually checking the condition if it is visible it will return true and uh change the location so now let's test this okay so as you can see the location has been changed of our door but now we need to smoothly change the location so for that what we need to do we need to add a timeline so let's make space and let's search for timeline there you go okay double click on it and let's add a float and after that let's uh let me name this to float value and now let's add two float keys for the first float key I'm going to give it zero time and zero value and for the second float key I'm going to give it one time and one value after that let's uh change the length to one and let's uh compile and go to the event graph after that let's uh connect the true pin to the play from start of the timeline and after that uh let's search for the lurp and connect the float value to the AL of the lurp now right click on the Node and click on split struct pin now grab the return return value and connect it to the location of Z now let's change B to 410 now what this will do this will transition from 0 to 410 location using this uh timeline okay so now let Let's uh let's actually compile and see if this works okay uh let's press f as you can see the door location is changing smoothly so uh now what we have to do we also have to close the door when we'll press the same key so to do this uh let's make some space and search for flipflop function okay let's uh connect the execution pin and from a let's connect to play from start of the timeline and for the B uh let's connect it to the reverse from the end of the timeline this will just reverse the transition so let's compile and uh test this okay so let's press F and F again you can see it's working but here is the issue if we'll spam the button uh the transition will look weird so let's fix this so let's make some space and here I'm going to use do on Note let's connect the execution pins so this node will not let us execute the further code until its value is reset when the timeline gets finished its value will get reset so let's compile and test so here I'm spamming the button but we are having no problem here so we are good to go but we also have to move the liever handle so to do this let's go back to our blueprint and let's go to the uh viewport here you can see uh we have to rotate the lever handle in the y- axis so let's go to our event graph again and here let's grab the lever handle and let's search for set relative rotation let's connect the execution pin and I'm going to change the Y value to minus 100 now let's test this you can see it worked but we need smooth transition so for that let's go back to our blueprint and uh here let's add one more lurp node there you go and connect the alpha value to the timeline float now right click here and select split struct pin so we can access these in the floats and let's change the B value of the love to minus 100 and from the the return value connected to its uh y- AIS now let's test this finally as you can see we are having a smooth transition between the door and the L handle both but now we want to change the size of this F key UI so for that let's go to our UI and uh here we want to change this button size somehow like this so for that let's go to our graph and here let's right click can make a custom event I'm going to name this change size and let's grab our uh button here this button and let's get it in the graph and let's search for set render scale there you go and let's connect the execution pin the default value of the size of the button is one but we want to change it to uh something smaller so let's duplicate and uh set it to8 I think it will be enough okay now let's uh connect the parameter and the execution pins now we need a delay between these so let's add the delay node let's connect the execution pins and we are going to give the delay of 0.2 seconds okay so now we need to call this custom event in our L blueprint so let's make some space and just after the do on node we want to call that custom event so we have the refence here so let's search for that event change size and let's connect the execution pins and I think finally we are good to go so let's compile and test it let's go near to the Li and as you can see now if we'll press the F key we can change the size of the button as we go away from the lever the UI has disappeared and as we gets near the UI appears again and and door are also working fine so that's all what we wanted I hope you like this video and if you do then do not forget to like And subscribe to this YouTube channel and I have also started a game def series on the game I'm currently working on so if you are interested in watching development of my game so the link is in the description and all my social media handle and game links are also down below so you can follow me or play my games till then see you bye-bye
Info
Channel: Vercion Games
Views: 667
Rating: undefined out of 5
Keywords:
Id: 6drKIwRMMTY
Channel Id: undefined
Length: 13min 25sec (805 seconds)
Published: Wed Feb 07 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.