The Ultimate Doors Guide! │ Unreal Engine 5 Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello there people of the internet um today we're making these Advanced doors so you can open them regularly just like this physics works with door these doors as well um they open horizontally and vertically um obviously you'll be able to make them go up and down and left and right and whatnot but yeah just basics of what we're going to be making today so yeah let's jump right into it okay so the first thing we're going to want to do is we're going to want to um start making the door blueprint so we're going to make a photo called door and then we're going to make a blueprint actor uh called bpor door uh this is cuz we want to put the door inside of the world so all right let's open that up so in the door blueprint we're going to add a static mesh uh we're going to call that door door and then inside of here where it says static mesh we're going to apply the door static mesh smore door if you don't have this in your project already uh it's in starter content and if you don't have starter content uh right click on your content browser add feature or content pack go to content and add start to content and then you'll have the door so what we're going to do now is we're going to add a blueprint interface and now what a blueprint interface does is it allows us to share data with other blueprints uh without have to without having to directly cast to them so we're going to create a BPI interact this can be recycled in your blueprints as well uh just to say pick up objects and stuff interact with other objects so yeah and we're going to add an input which will make uh instigator like whatever interacted with it it will most definitely be the play character just instigate that will be an actor reference nice so next you're going to go to back to your door and go to the implemented interfaces and we're going to add our BPI interact interface perfect so once we do that uh we can get rid of these for now still in the door blueprint we're able to now you see this event interact here great we're just going to add a print statement for now and we're going to print out interact uh this is just to make sure it's working and everything is functional great so we're going to do next is add an interact key so in third person input uh you can add action inputs like this we're going to add a new action input under input input action and we're going to call it IIA under _ interact we do that we're going to go back into the IMC default uh this is for the context and we're going to then imp we're going to implement in here the interact and we're going to make that key e great so next thing we're going to do is we're going to grab I aore interact and this is just our e key pretty much so now for the interact there are two ways you can actually go about doing this you can do a Trace uh line Trace by channel uh this essentially sends Ray cost um from the start position to the end position uh for us it would be start position the camera and then end position around 600 m in front so the other option is uh to add an interact box to the door and uh interact with it from there I'm going to be showing you how to do both and you can pick and choose whichever Bo your game I would suggest the interact from the door one as it's more commonly used in games it's simpler but here we go okay so what we're going to do is we're going to grab our follow camera out we're going to get us World location then we're going to this to the start so pretty much the line the line Trace will start from the play C the play camera and we want it to end with the same rotation of the camera but like a couple meters in front so to do that we're going to get the world world rotation this time not location World rotation and from the world rotation I can't talk we're going to get the forward Vector then from the forward Vector we're going to multiply it by we'll just create a float you could just two float and then input whatever number you want but we are going to actually create a variable for this we're going to call it travel distance and it's going to be a float and we're going to make this uh around 600 for now and we're going to put it into this multiplication after that we're going to add the world location and the for Vector together and that forms the end okay so once you've done this um what we're going to do is we're going to add a branch here and we're going to break the hit result like this once we do that we're going to check if the hit actor implements the interface so does implement interface and we're going to see if it implements BPI interact so what we're going to do is we're going to create a branch it will come off the true of the one we just did for the line trace and that's just checking if it implements the tract interface if it does and it's someone we can interact with so then we're going to come up with hit actor and we're going to just type in interact and it should come up with interact message which is our interface actually and the instigator it'll just be self perfect so now most likely what you're going to need to do is go into s content props and into your door what you're going to want to do is just add simplified Collision I've already done this for mine but just add that and we should be good to go so if you put your door into the world like this um what you should see is when you click e to interact you should be presenting interact which is great exactly what we want okay so now we're going to work on the door logic so we're going to promote this instated to a variable and we're going to call it player reference or player ref for sure uh this this is just a reference to the player uh which we're not going to use but if you wanted to use it for whatever it's right here and you have it then what we're going to do is we're going to create a variable called is door open this will be a Boolean uh which will basically just see if the doors open exactly as the description is so we're going to make a branch and we're going to connect the is door open to the Branch then out of the true we got to set is door open to if R then not not a not equal not Boolean so what this does is it sets it to Whatever It Isn't So when you open the door so if the door's already open it will set it to close if it door already closed it will set it to open as simply as that perfect right so now what we're going to do is we're going to create two custom events the first one's going to be called Open Door second one's going to be called close door perfect so we're going to add a timeline uh this timeline we'll just call door interact and out of the open door we're going to put into play and out the closed door we're going to put into reverse so this is great so this might not be the most efficient way of doing it but it's one of the ways I discovered so what we're going to do is put the length to 100 add track add a float track and we're just going to call it rotation then we're going to add a key by right clicking here add key we're going to add a key of Time Zero value zero then we're going to right click to add add another key and this will be time 100 and value one perfect so then out of the update we're going to want to update the doors relative rotation relative rotation so this node gets the door the door which is relative to the event graph here instead of the world and we're going to set it new rotation to pretty much be this rotation here with these two nodes cannot go into each other so what we're going to do is we're going to break this sorry we're going to split this now you may be thinking just put the rotation right here into one of these but that won't actually work as the value is uh Zer to one and we don't want to just rotate our door by one so in order to make it say let's say 90 we're going to lur which is a linear interpolate and we're going to plug the rotation into the alpha so what the lurp does is it will interpolate between two different values so it Blends between two different values um by this Alpha here which is connected to the rotation so we're going to make B let's just say 90 for now and then we're going then we're going to connect it to the rotation here perfect so before we can done we are going to set the playback speed of the timeline so to do that go to components and drag out your door interacts which is the name of the timeline we're going to just set playback play play rate there we go that's what it needs to be play rate and then just plug it w back in do it for both these just like this and then make the target of the second one door interact as well now that's great so in order to do this correctly what we're going to do is we're going to divide both these and in the Top Value put 100 so we're going to promote these both to variables the first one we're going to call open speed and the second one we're going to call close speed so I'm going to set these both to one you can select whatever value you fit your game uh just quit warning these are in seconds you don't want to be S to 100 because it'll take 100 seconds for the door to open unless that's what you're going for you know I'm I'm not going to judge you all right so once we've done that we're going to do out of the true we're going to close door out the false we're going to open door like that perfect going to rearrange this real quick great so now if we click play what's going to happen is when you come up to the door you'll be able to open it and you'll be able to close it just like this So yeah thank you guys for watching this is all we do no I'm just joking of course this is just it but this is the basics to the door pretty much you know you can mess about with it it's it's a door what more you want but okay so you'll probably notice the first issue is they open it from this angle yes we're getting shoved out the way we're glitching inside of here it's it's not great lie so we're going to make it dynamically open so when we're this side it will open not this way but the other way and this side it will open just like this perfect all right let's go do that then okay so just before we do the dynamic door we are going to make some of these values Exposed on spawn like is door open open speed and close speed after that we're going to go to the viewport and we're going to add a box Collision just like this and we're just going to put it around like this I'm going to turn snapping off I'm just going to position it to how I want it so we want to put it in front of the door something like this and we're going to expand out a little bit and just make sure it's expanded forward a bit and just make sure it's in front of the door and it's not like and it's not like over here make sure it's right here just like this okay so once we do that we're just going to click on the box and do contrl + C contrl V to duplicate it and we're going to move on to the other side just like that okay great so now what we'll do is we'll right click on box we'll add event and we'll click add on component begin overlap and this will just uh trigger every single time our player character overlaps with the Box first of all though we're going to check if the other actor is the player character this is just so if you have ai on the game uh it's not just triggering to anything it interacts with with and only the player so we'll make a branch and we'll connect up to the branch after that we're going to make a variable and it's it's going to be called open dynamically we're going to put question mark at the end and we're just going to see if it's true going to hold B to create a branch we just going to see if it's true and if it is going to make a new variable called should change going to set should change to True great compile and save okay we're going to go back to the open Dynamic variable and we're going to click this I button which exposes it on spawn so we can actually edit it over here see all these values we can edit all of these so now we're going to do the exact same for the other box we're going to right click add event on begin overlap and we can actually just copy and paste contrl C and contrl V all this over and then connect other Rector back into this equals and just uncheck this should change then we're going to create another variable called open Dynamic value this is going to be a float and we're just going to set it on one or minus one depending on pretty much this all right so we're going to go back over to the timeline and just where set play rate is we're going to make a branch and if should change on the open if should change is true we are going to set the open Dynamic uh value to minus one and if it's false we're going to set it to one and then we can connect both of these up to the play compile and save okay so now we're also going to set the default value of open Dynamic value to one par save okay so over by this blur we're actually going to promote this to a variable and we're just going to call this open oh open Rotation we're going to call this one close rotation and you can just click the arbow for these as well and say yeah that's good pil save okay and then we're going to drag out of open open Rotation and we're going to multiply it by the open Dynamic value okay so once we've done that it should be working in theory so we're just going to test it so click e we go to the other side and oh yeah silly me we haven't actually said open Dynamic here so you're just going to tick this and once you tick it it should then work so you can close it and you can open it on the other side that's good perfect so the next thing we're going to do is I don't know if you can see but when you're like closing the door you can like glitch inside of there so we're going to disable the Collision on the door when it's opening and closing just it's a bit smoother all right let's go do that okay so when the door blueprint coming off of of uh we'll just make some space coming off of here we're going to just set Collision enabled on the door we're going to set this no Collision like that and we're going to do it for uh here as well just copy that door reference no Collision plug it back into the reverse and then make some more space off of the finished we are going to drag out the door reference we're going to set Collision enabled to be query and physics Collision enabled quer query and physics there we go that's perfect and then when you open the door you should now just be able to walk through it like this so you'll no longer bug inside of the door which is exactly what we want so that's now the open Dynamic part done and in theory this is all you guys want your door is done pretty much uh yeah your door is pretty much done uh one more thing we can add is a frame to the door which just looks a bit cleaner which we'll go do now so in your BP door add a new static mush we can call it frame and if you install the starter content you should have a door frame just like this in the viewport we're just going to line this up with the door so I found that minus 45 is good and it just lines up with the door perfectly and save and we can see how that looks now as you can see now got a nice door frame which is just perfect all right so what we're going to do now is we're going to add interact you'll be able to interact with the door and it will bring up a widget so we're going to make a new folder and we're going to call it widget double click that to open it and we're going to go to user interface widget blueprint user widget and we're going to call this wbore interact going to open this okay so we're going to go to the top right corner and where it says fill screen we're just going to put it on custom we're going to make the width 100 and the height 25 then we're going to drag in a canvas panel from the library like this and you should be seeing this now so then what we're going to do is we're going to drag in another canvas panel and we're going to get an image and connect that to this canvas pan panel here so on the canvas panel we're going to resize it to 25 and 25 and we're going to set the image to be centered and we're going to just set the position of X and Y to zero and the size to be 25 25 then we're also going to set the alignment to 0.5 and 0.5 then just this is mainly for design preferences I'm going to just set the color to like a grayish sort of color okay then what I'm going to do is I'm going to add text I'm going to add that to the canvas panel and in the text I'm just going to put e since that's our interact key uh size the content then we're going to Anchor it to the center and make all the position values to zero just like that we then want to set the alignment to 0.5 and 0.5 and you can always scale the font size down a little bit just so it fits in something like that it's great okay then what we're going to do is we're going to add another canvas panel and we're going to connect it not to this canvas panel but the first one we made and we also want to scale this down so you can just drag it in here like this which is great then in here what you're going to add is a text box and that will just say interact we're going to make it size to content we make the font size I like 15 and It just fits in there perfectly I'm also going to Anchor it to the sort of left here and set the Y position to zero then set the alignment to 0.5 by 0.5 and actually we're going to set this one to the zero like that okay so now we made the widget we're actually going to make it work in the door blueprint so over in the door what we're going to do is on the viewport we're going to actually make another box collision and we're going to call this interact mine parented to the frame oh we can't call it interact we're going to call it interact box instead mine's connected to the frame but if it's parented anything just hover over it and you can unpairing it like that then to position it you can just do it like how I did the last one however this time it's going to go over both sides something like this try to keep it sort of inside this box here for the best sort of effect pretty much uh this is good for me so yeah then we're just going to make it sort of in the middle like we did the last one like this that looks good to go uh you could just expand out a little bit like this and yeah it's a good in trct box so basically whenever the player is inside this box uh the widget will show and they'll be able to interact with the door so let's go Implement that now okay so what we're going to do is going to go to the interact box right click it add event and add begin on component overlapped and we're also going to right click it again and add event begin on component end overlap and we're just going to check if the player is in this box Collision like we did over here so we're just going to get the pl character and we're going to check if it's in the Box Collision we're then going to link this up to a branch just like this you can hold B and then just click to get Branch if you need to and for me I want the uh widget to appear in the world so in order to do that what we can do is we can search in the ad for a widget and we can make this screen and screen and draw a desired size tick and where it says widget class here we're going to put WB interact in okay so then we're going to position the widget to be let's s in the center of the door like this and almost forgot you want to make the draw size 500 by 100 just like that okay so once we do that back into the event graph right at the top so at the top here we're going to make a new event called begin play and now this will just execute every time you start the game so what we're going to do is we're going to grab the widget we going going to get widget like this and we're just going to cast to wbore interact just like this and we can right click to promote the variable and just called it WB interact like that compile and save then coming down here we can just drag out from this widget here and we can set visibility out of the true set the visibility to true and then we can just copy and paste all this logic over to the end overlap as well collecting the other actor here we just uncheck the set visibility like that compile and save we're going to do is we're going to create a new variable again called can interact and we're going to make that Boolean and we're going to set it over here to be true and over here to be false then we're going to make a branch I'm going to make another variable called is line Trace so this going to make us choose whether it wants to be line trace or a collision sort of based interact system so go ahead and just get this line trace and connect up to the BR once we do that we're going to get player controller and we can just set enable sorry not set just enable input like this and make the player controller the player controller instead of the target like that then drag back out of player controller and get disable input and do the same thing drag into the player controller slot just like this okay so now what we're going to do is we're going to just uh get a new event which will be the E key we can find it here it is the E key and we're going to make a branch and this Branch will have can interact here so if Canon interact is true we're going to get another branch and we're going to get line trace and if we're not using a line Trace then we're going to interact not that one interact and it'll need to be cool function interact like that and we don't need an instigator for this one okay so now we only have a couple more things to do now uh for the door for the basics of the door to be fully done um so what we're going to do is we're going to go to the widget and we're actually going to just go to visibility and we're going to set it to false and then also over here where you plug enable input into true we're actually going to put it into false okay so now in theory this code would work except it doesn't as the line Trac is triggered as well as this so the door will open and close at the same time meaning the door won't do anything so in order to fix that we're just going to grab the door with going to set Collision profile name I'm going to write in here porn we're going to copy and pastees over here and then in here we're just going to write block then all about like that then it should work so you should be able to go to the door and interact with it matter if you look in the door or not so say we're looking this way you interact with it this way you can sit interact with it which is perfect another thing you might want to do is just make line Trace instant edable instance editable right here so what you want going to do now is when the door's closed we want the interact Tex they open and vice versa the other way around so in order to do that what we're going to do is go to WB interact and where it says this text interact we're going to rename it to interact and we can just tick his variable like that now what we're going to do is we're going to head over back to the BP door and over back where the timeline is so we're going to go back to this WB interact which we created a while ago and what we're going to do is we're going to then get interact which is the variable we literally just created inside of the widget then we're going to set text and I mess this one here and we're just going to link this up here just like this there we go something that you might forgotten to do what I did uh you actually want to link this here so it connects into that all right that's good then we're just going to call this close and we're just going to duplicate it to the other side and we're going to put that as open plug it back into the reverse okay so now what you should have when you walk over the door now it should say close and open like this so you may have seen the first time you look at the door it says here eat interact and then when you interact it tells you you can close it open the door uh we're going to go fix that right now so in BP door we're going to do is we're going to create a new function we're going to call this function start with door open right then we're going to create a branch by holding B and clicking and we're going to link up is door open to that then off of the true we're then then just going to call the Event open door and off of the false we're going to call the event closed door then we're going to get the wbore interact again we're going to get the interact variable then we're going to set the text to close on this one control D to duplicate then we're going to set to open on this one then what we're going to do is we're going to connect this function up to the begin play uh the way we're going to do that is we are going to just simply put it here for now like that perfect then when we play we should have e to open and then e to close and that is now the basic door done the next thing we're going to do is we're going to add a physics to the door so if you apply the door to have physics you'll be able to run through it like in GTA okay so in order to do the physics door what we're going to do is we're going to go to the frame we're just going to get the collision and we're going to set it to no Collision as it can interfere with the physics of the door then what we're going to do is we're going to add a physics constraint to not don't parent to anything just put it inside of the default scene route and we are going to just put it to the middle for now going to say this location just zero for now there we go then what we will do is we will change the component name to be this exact name here for me it's door whatever you've named your door mesh you're going to put right here so going to put door here it should highlight the door red like this after that we're going to go down to where it says angular limit we're going to make swing swing two motion to be locked twist motion to be locked and we're going to set swing one motion to be limited so what this does is it locks the rotation of the door so instead of being able to knock down the door uh it just rotates like an ordinary door so we're going to set the swing limit so I found a value of 100 works really well for this sort of door then we're going to go down to angular motor and we're going to change this to twist and swing and just set up swing like that perfect once we do that we can add a new variable and we can call it physics door and we're going to make that instance editable now from begin play we're going to add a branch here and we're just going to put in physics door because we don't actually want to run any logic if it's not the physics door because there's no there's no point then we're going to create a function called initialize physics door now what this will do this this will get the door ready to basically have physics applied to it inside of this function we're going to set simulate physics of the door to be simulate and then we're going to set Mass overriding kg of the door and we're just going to set that to a variable which going to promot this to a variable and we'll just call it Ma like that I'm just going to set this variable to 60 that'll be how heavy the door is so if you got light door set to a light door heavy door set it heavier you know then we're going to go to the physics constraint and we're just going to set angular swing limit swing one limit we also going to promote this to a variable too and we'll just call it swing limit we're going to set this to of 100 as I found that's a good value for the swing limit and then we're going to go into the door get a reference to the door set angular dampening to a new variable and we'll just call it damping D not damping here we go so what this does is it enables the physics of the door uh then it sets a custom Mass to the door of how heavy the door is so it's how heavy it is to open uh it then sets the swing limit so how far around it can swing obviously you don't want to be 360° and then you set the angular dampening uh for the closing so it doesn't like constantly swing back and forth back and forth until it stops it stops quite immediately so finally what we're going to do for the physics door is we're going to come off true and we're just going to initialize physics door the function we just made and that should be everything we can test we can test it now so what I'm going to do is enable physics door and it should work which does is it works to a certain degree so what we're going to do is we'll to make it so you can't interact with the door as it just bugs everything out that's what we're going to do next we also get all these errors here so we're going to solve all this okay so down here uh the second box Collision where we do the interact uh we are going to just come off of here like this make a branch and just plug into this Branch physics door if physics door is full then we can do this and same here contrl C contrl + V and if it's false then we can do this then finally we're going to do check on the event interact which is over here here we're going to do a check which just checks if it's a physics door so B for a branch is physics door if it's false then we'll do this so the physics door should be working as in the fact that you won't be able to interact with it anymore you'll just be able to push it open like this now to make it so the door can close what we're actually going to do is in the blueprint go over to where your door is and we're just going to put the Z axis of the location up by 0.5 and now your door will work so you about to swing it and it'll shut like that however as we can see the door is sort of been a bit weird here and that's just because you want to set the damping to 15 then your door shouldn't do that anymore it'll just close like that now there's your physics door okay so the final thing we're going to do is we're going to make horizontal and vertical doors uh these happen to be actually pretty simple so let's go right into it so we're going to open the BP door going to go to the event graph and we're going to make a new custom event uh just find some space for it I'm going to put it here at the bottom make a new custom event and we're just call it open we call it open slide door and I'm just going to correct that spelling issue there then we're going to make another custom event and we're going to call this close slide door so for the logic Y is going to be pretty similar to the door we have up here and in fact we can just copy here copy these four here crl + C and then crl + V we could just reuse this here like this and and we could even do the same for the timeline so what we're going to do is this might get a little bit confusing but it shouldn't be too bad so pretty much what we're going to do is come here to the interact here and then the timeline as well and that's all we're going to copy come back and then you should find this will actually work what we're going to do is replace this reference here with the go into components we're going to rename this timeline to be door slide open find the timeline and we're just going to then connect it over here at the set play rate just like this so once you've done this what we're going to do is we're going to create a new variable and we'll just say is door ver vertical oh that didn't work we're going to call it is door vertical question mark going to be a Boolean and going to go to our branch in the update we're going to check if it's vertical we're also going to make this instance Ed editable as well same with the dampening swing limit and mass compile and save so coming out the false what we're going to do is we're going to set the relative location relative location of the door and we're going to split this structure here just like that then from this rotation we're actually going to L linear interpolate it then what we're going to do is we're going to create a couple new variables one which is going to be called horizontal slide close location and another one called horizontal slide open location so I'm going to leave I'm going to make both of these floats I'm going to leave the Clos location is z and I'm going to make the open location to be 100 and save then this B will be horizontal slide open we're going to make this rotation be the alpha and make the Clos location be a like this then to make it so we can decide if we want the door to go left or right we're going to make make a variable called is right this will be a Boolean is right this will be a Boolean then we also going make another variable and it will be called left and write value and this one will be a float we're then going to multiply this by the left or right value we're going to set the default value to one just like that I'm going to plug this into the location X the location y like that so now what we're going to do is we're going to go back into the functions and we're going to create a new function and we're going to call this initialize horizontal horizontal door we're going to go to Branch we're going to just make this horizontal right or is right like that then left or right back value we're going to make this minus one then we're going to make this one so what this is doing is it's multiplying the lurp by either one or negative one and negative one will make it go the opposite direction so then at the begin play we are going to make a sequence and we're going to plug the start with door open to the zero and it start with door one sorry no then one to initialize horizontal door like that compile and save okay so now what we're going to do is we're going to make another variable and we're going to call this is horizontal slide we're going to make this a Boolean instance editable and the same with is right we make that instance editable as well once we do that go over to where event interact is after we decide if the doors open or not we are going to make a branch and then come off this with an or and we're going to see is horizontal slide or is door vertical and we're going to copy and paste this over here and make this come off the false so on both these if it's false we just want to open door on the bottom one and if it's false we're going to close door on the top one however if it's true we're going to close we're going to close slide door and if it's true on this one as well we're going to open slide door just like that so now if we check we should be able to make the door instead of uncheck physics door going to uncheck line trace and we should be able to make the door is vertical to be yes we should be able to take is sorry we haven't set vertical yet but we should be able to check his horizontal slide see yes we should be able to go in the game and it will slide like that now the door is actually the wrong way around funly enough uh so that is the left and then the right like this we'll slide right which is exactly what we want all right perfect so we have this issue where you can't close the door and that is just because I was being dumb so if we go back to here we should be able to just connect these both back to the open like this and then you'll be able to close the door I was just being kind of dumb but yeah it works perfect so now we're going to make the door vertical so let's do do that it's very simple it take five more minutes let's go so in the blueprint door we're going to go down back to where the sliding is and we're pretty much going to copy and paste this entire code and then put it up here we're going to change very minor things and one of them is we're going to change this location to The Zed simple as that so technically this is now done but for better use we want to re name these variables to be more appropriate names for the vertical door so pretty much what we're going to do is just create three new variables one of which is going to be vertical slide close location make that float next one will be the next one will be vertical slide open location and finally we'll have uh up slash down value and sorry it's four variables we also want the is up bran like that perfect then we're going to make a final function and we're going to call this initialize vertical dra and we're just going to get the Boolean is up branch connect this to the branch and then up or down value we're going to make this one here and we're going to make it negative we're going to make it negative one on the false so we're also going to default the up or down value to one just like that something that I forgotten to do though we we need to change these variables completely so plug the rotation into Alpha plug this vertical slide Clos location to a and the vertical slide open location into B then off down value into the multiplication so now what we want to do is you want to make is up instance editable and you're going to go all the way to the top for the big in play and you're going to connect the fun function initialize vertical door to begin play now when you play you're able to decide if it's vertical and if it goes up we'll we'll check both of them for the F for the test for the first test and it goes up and it goes down and if you uncheck is up your door will go down and it go back up so yeah that's everything thank you guys for watching make sure to subscribe leave a comment what my next tutorial should be and yeah thank you adios
Info
Channel: MrKnowBody
Views: 3,313
Rating: undefined out of 5
Keywords:
Id: axTbgVeOKes
Channel Id: undefined
Length: 51min 22sec (3082 seconds)
Published: Sat Jan 06 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.