How To Open Individual Drawers (With Model & SFX) - Unreal Engine 4 Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back to another management 4 tutorial in today's video i'm going to show you how to open and close individual drawers like we see here so we've got a chest of drawers here i'm going to be able to open and close each individual one and play a sound effect at the same time and have it look great so i'll show you what this is going to look like so if we hit play i'm just going to go into first person here and if i press e on an individual draw it's going to open if i press it again it will close and these red lines are here just for testing these can disappear afterwards so we don't have to have those on we can remove them but we can click on each individual draw and it will open like so when you're looking at it and pressing e as well and we can open more than one at the same time so we can open them all if we wanted this is just what we're gonna make and it looks great so i'll show you how to do that now so i'm gonna do first is create a new folder to keep this nice and organized so i'm going to right click create a new folder i'm just going to call this drawers like that open that up and then i'm going to import everything that we need so i'm going to leave a link in the description down below to this 3d model of the drawers and the two sound effects which i'm using for the opening close like say i'll leave the links in the description down below for you to use those as well so we just drag and drop them in to import them hit import all like so and now we have those in there like that so i'm also going to do is create another folder called mats just to keep this a little bit nice and organized looking a little bit better move there like so and then the next step after this is going to be to create our blueprint actor that we're going to be using so to do that we're going to right click go to blueprint class and get an actor i'm going to name this draws bp but you can enter whatever you like and then open that up straight away what i'm going to do is i'm just going to minimize that and then select all of these so actually those shouldn't have been matched but that's fine so just select all of these static meshes that we have for the drawers so this is going to include the actual drawer itself and all the individual drawers which you can open so select those go back to the blueprint and then add component and add static mesh multiple assets now we have all of those in there like so what i'm going to do is just unparent these like that so they are all at their own separate thing so they have no parents like so so that is now working great like that so straight away what we're gonna do is just go over to the event graph here now we're gonna delete the begin overlap and event tick notes and off of event begin play we're just going to enable input so enable input like that with the player controller as get player controller and this just allows us to actually use our interaction key or whatever we like in here so we can compile that and that will actually make our interaction key as well so i'm going to edit project settings and when this loads we're going to go down to input so input down here and then we're going to open the action mappings hit plus to create a new one and we're going to call this interact like so you can set this to the e key the f key left mouse button anything you want and you can have multiple ones and this is also great for setting up key bindings later or using it on multiple consoles or anything like that this is just great and how to do that so you open that up like so and you can close that go back in the blueprint event graph here and we'll just right click and search the action mapping we just made i called mine interact like so out of the interact what we're going to do is we're going to cast to our character so mine is the third person character so cast to third person character this can be first third or anything that you've named it the object is going to be get player character like that and the reason we're doing this is so that we can access the camera location for our player so then out of this what we're going to do is come out the execution node and we're going to line trace for objects so line trace for objects down there like so the object types we're going to come out and we're going to make array with the array as well static like so and now the start and end is basically where we want to start and end this line that we're going to draw so the line trace is essentially we're drawing a line so we want this to go from the player's camera location just in straight line forward so as third person character we're going to get our camera so for me that's just the my fpp camera so first person perspective but you can just get your camera that you're using and out of that i'm going to get world location so get world location like that and plug that into the start out of the camera again i'm going to get the forward vector so this is just the forward direction facing the camera is so when you've got the camera it's going to go straight out in front of the player coming off that and we're going to get a multiply so a vector multiplied by a float and the float i'm going to put as 500. this here is how long you want the line to be so if you want the line to be shorter set this to a value lower than 500 if you want to be higher set it to above 500. i've just chose 500 as that is what's good for me and then out of the get world location again we're going to do is get an addition so vector plus a vector i'm just going to add the multiplication together to that as well and put that in the end and what that's doing is that's just appending it to make sure it's a straight line in front of the player and so that is how we're going to be drawing the lines so it's going to start from the camera and then go 500 units in front of the camera and end there in a straight line then after this what we want to do is come up with the return value of this line trace we want to get a branch like so plug that in there and the out hit we want to break hit result like so and open up the advanced settings there like that out of the hit component for the brake hit result what we want to do is cast to static mesh component and plug that into the true of the branch so what this is going to do is if this line trace hits an object if this line trace hits an object what it's going to do is see if it is a static mesh and if it is a static mesh it will fire off this code if it isn't it won't do anything and also that's just reminding me the array doesn't want to be world static it wants to be world dynamic because we want to be able to move these objects as well so they need to be movable hence well dynamic not world static so i'm back off of this cast here we want to do is as static mesh we want to get relative location and they transform there so get relative location right click that and split the structure pin and we're going to come out with the x and we're going to get a greater than or equal to float and i'm going to set this to 30. now the reason i'm doing this is because that's how far out i want the draw to go so if we can go on here you see that on the x it's going out by 30 because i want it to go there so i've moved it by 30 on the x so set that to be how far you want it to be and i'm doing this here as well is so that then if it is greater than that it's going to go backwards so it's going to reverse this and go back in instead so now the return value for that that's just going to go into another branch with that going into the cast like so and actually i'm also going to get a knot as well sorry so get a not boolean out of that and that then goes into the branch like so so if it is not like this so you could have used a less than or equal to but i just want to do it this way instead then out of this this is where we're also going to play the sound so out of the true of this branch we're going to play sound at location like so this sound is going to be the open as this top one is how we're opening the draw so this is going to be open draw sound effect like so and then we're going to duplicate that plug that into false so play sound location off of false as well and this will be the close draw like so location what we're going to do is just get actor location get actor location like so and plug that into both of them and it can just be self as it's just going to be where the draw is any target can be self as this is just going to be where the draw is so that works perfectly like so so now we're going to play the sound effect and then what we want to do is actually move the draw in and out so to do that what we're going to do is i'm actually going to promote this to a variable so we don't have to have loads of blue lines everywhere so right click as static mesh component promoter variable and i'm going to call this static mesh ref like so and just plug that in there like that just to keep it nice and organized and looking a lot neater so do that like so and then come back over here and we're going to get that reference so we're going to call that so get static mesh reference like so i'm going to get world location this is going to get the location of the static mesh that the line trace has hit so the player is looking at just move it up a bit like that and what we're going to do is we're going to right click the return value and split the structure pin and then we're going to create two new variables as well so hit the plus variable down here and this is going to be called the start location and as i call it location we obviously want this to be a vector because that is the location variable and then we're going to create another variable and call this end location like so but you can call this in location and out location start and end anything like that what we're going to do is we're going to set those so come up with the play sound location and just set these variables here so set start location and set end location what we're going to do is also right click on these return values and split the structure pins of those as well as we want to mess about with the x y and z individually so for the start location the x y and z are all going to be the same so plug those all in like that and then for the end location the y and the z are going to be the same but the x we want to add 30. so again that's because like i said earlier i want to be moving this outwards on the x like so so we can do that like that so if i then come out the x and add a float plus a float like so and then if i add 30 we can then plug that in there like so and actually i've just thought if we don't do world location but we get relative location so get relative location like that and then split strike spin and do the exact same thing this means this would then work no matter which way it is facing so if we rotate this in the world this should still work so that now is a lot better just suddenly remember to do that so now we've got that working like so so now we're going to set the start and end locations for our draw i'll just add these three row notes here just to make this a little nicer to look at like so and now what we want to do is actually move it so we're going to come out the set end location i'm going to add a timeline add timeline like so and i'm just going to call this open draw and this is going to go from play from start not play and what we're going to do is double click that to open it up and we're going to add a float track this i'm just going to call open draw again doesn't matter too much and the length i'm going to set to 0.5 so this is how long you want it to take to open the draw i want this to be very quick so just half a second like that and i'm going to right click on the graph add key to curfload time zero value zero so this is a very start add key again time 0.5 value 1 so that's then at the very end like so so that is now our timeline set up so we compile and close that now to actually make it move what we're going to do is come out of the open draw flow track we made and get a larp vector so we look for a vector like so the a and b are going to be our start and end location variables that we made so a is going to be our start b is going to be our end as we want to move the draw between our start and end locations and then what we want to do is just then get another reference to our static mesh here so static mesh reference we want to set relative location so set relative location like so and plug that to the update with the new location as a return value from the lob like so now what this is going to do is when we press the line trace if it hits a static mesh in this blueprint what it's going to do if it hasn't been opened already it's going to play the sound and open it and then if we have open already we're going to do this but reversed to close it and also one other thing on the line trace here we need to untick ignore self so it will actually be using and looking at the static meshes in this blueprint as well so if we come back over here and like i say we're just going to reverse this for the closing so to do that we can simply just copy and paste all this so select all this copy and paste down here like so i'm just going to move this down to be underneath instead just to give us a little bit more space like that and then again plug in the set into that play sound there like so and the only thing i'm going to change here is this isn't going to be plus 30 this is going to be minus 30 on the x like so so -30 and again you can customize that to be on the axes which is for you and your mesh and however far you want it to go out and so now that should work everything else should be the exact same so compile and save that go back into here we can drag and drop this blueprint in so drag and drop the blueprint in there and if we hit play you can test this out so i'm going to first person and then if you see we hit that that's going to move which is obviously not we want and that's because we need to change that static mesh to not be movable we want that to be static so that one can't move so now if we try this again this should work so we hit it it hits a draw it's then going to open up the draw that we want so we're pressing e on the specific draw we want to open and it's going to open it play the sound effect and if you press it again it will close it like i say we can open up all of these if we want to now if you press it too quickly it's going to break and do that so an easy way to fix that is just make it so the player can't spam click this so to do that what i'm going to do is just right at the very start here i'm going to get a branch so if i just select all that and move it over i'm gonna hold down b left click get a branch plug that in there and i'm gonna create a new boolean variable so here variable here and call this one can open question mark and make this a boolean like so default value of true and plug that into the branch there like so and then what i'm going to do is straight after this branch actually i'm going to set this to be false so set that to be false like so and then at the end over here off of finished of these timelines what i'm going to do is set this again but to be true now so this means that we can only open the draw again once we've finished opening another draw so now if we try this again we can see that this should now work a lot better so i can't open another draw until that one's finished meaning we now don't get that glitch again anymore so again this just means that we can now open and close these all perfectly so we can't open one when we're opening another one but as it's just half a second it's very quick the player shouldn't notice and this just now works a lot better and it doesn't break or glitch you can see as well if we rotate this so it's facing this way this should still work as it was relative not a world so that still works like so and as you saw that was a bit glitchy when we rotated it it was going further one out so if we change this from 30 down to 25 that should work a little bit better as it was just a little bit glitchy when we rotate it but now we can open and close this perfectly like so no matter which way it is facing and where we place it and then also one other final touch sorry is off the false of this branch we want to set can open to true as well because otherwise if we press e and we don't hit something then we're not going to open again so if we then set that like so we'll be able to hit e here and then we can now open and close these like so so i think that'll be for this video is we've done everything we want to do we've created this set of drawers which we can open and close each individual drawer as we like and it plays a sound effect for opening and closing and this looks and sounds perfect so like i say we can open each individual one and then obviously you can put something in there which the player can pick up as well if you would like so that works perfectly so thanks so much for watching i hope you enjoyed and i hope found it helpful and if you did make sure to like and subscribe down below so thanks so much for watching and i'll see in the next one bye
Info
Channel: Matt Aspland
Views: 20,701
Rating: undefined out of 5
Keywords: ue4, unreal engine 4, unreal engine, tutorial, ue4 tutorial, unreal engine 4 tutorial, how to make a game, how to, 3d modelling, blender, unity, games design, graphic designer, ue5, unreal engine 5, drawers, chest of, chest, dresser, dressing, table, open, up, each, individual, every, single, draw, close, sfx, free, easy, quick, model, 3d, sounds, audio, sound, effects, effect, line trace, linetrace, desk, counter, box, cupboard, bureau, all, by, looking, at, it, them, interact, key, horror, hide, quest, for, mission, cross hair
Id: x7q4Ans3mPk
Channel Id: undefined
Length: 14min 36sec (876 seconds)
Published: Mon Nov 16 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.