How To Hide In A Locker - Unreal Engine 4 Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome back to another management 4 tutorial in today's video i'm showing you how to hide in a locker like you can see here so we have all these different lockers i've got some against the wall and all of them facing different directions just to show you that with this one blueprint we can hide in each of these individual lockers facing different directions so we're going to press a button to get in we'll hide in it the door will open and this will also hide this from an ai so the ai won't be able to see us so i'm gonna hit play and i'll show you what's gonna look like now so again i'll go in first person i'll walk over here i'll press h whatever button you want door opened we got in or closed and we can move our camera around in here like so and then get back out again like that and this works in all of these along this wall like so and get in and out like that and you can have them closer you just need to lower the size of the box collision which is very easy and i'll show you that later and then this also works with whichever direction they're facing so you saw it facing the other direction we've got this one we've got this direction and again we can see out of it so we can see the other locker which will also show that this works here as well so this is what we're going to be making today very simple one blueprint that's all it is and we can have as many lockers as we like so let me delete this code and i'll show you how i've done this the first step you're going to take is you're going to want to import your locker static mesh now you can use any mesh you like this is just a very very quick and simple one which i made in blender earlier as i couldn't find any online which worked because what we also need is to make sure that the door rotates properly so again it's a very very simple one which i made about five minutes but when you want to make sure is when you import it you have the locker and the door as two separate meshes as you can see here and when we have the door we have it so it will rotate on the side like that so you see the axis point is on the side and rotate it like you would a door you only need to do that if you want to be able to open the door so just keep that in mind when you do that and of course you can use the one which i made as well i'll leave a link in the description down below to where you can download it from so once you've done that we're going to create our blueprint actor so we're going to right click get a blueprint class and get an actor and i'm going to name this one locker hide bp like so i'm going to open it up straight away in here what i'm going to do i'm just going to minimize it a little like that so i can still see it i'm going to select both of my static meshes so the locker and locker door go back into the blueprint add component and add static mesh multiple assets and then we have both of these in here like so i'm just gonna drag and drop that onto there to unparent it like that after this i'm gonna want to move it so the way i've actually modeled this is this is facing the wrong direction so if you're using a different model you don't have to do this and you don't even have to anyway i just prefer to do it this way so that it's then in line with other stuff so it makes the calculations later on easier because if we just add a component of a camera in here you can see that that is the forward facing direction so i want to have it like that so we're going to do is we're going to select both the locker and lock door and rotate it on the z by minus 90. now they're facing forwards like so then i'm going to select the lock a door i'm going to move it into position now a good position i found with this model earlier was 29.27 on the x 30 on the y and zero on the z so actually i might just round it up to 30 on the x as well so this is what we've got here so now the door is in position and you can just move it like this and again get it perfect for the values that you want for your locker and what we're going to do next is going to compile deselect that and add another component and this one is going to be a box collision like so i'm just going to scale this up as well so i'll move it over so it's just in front of locker as well i'm going to scale it up so i'm going to again using the values so i found to be quite good earlier that was 4 on the x 3.75 on the y and about 3 and a half 3.5 on the z again customize these values to get them perfect for you and the reason i'm moving out in front as well is so that you can only enter the locker if you're in front of it so you may want to lower the wire a little bit like so so you have to be basically directly in front of the locker in order to be able to open it and that is how you do that there and i think that looks quite good for me next i'm going to deselect that again add another component and this one is just going to be a camera i'm going to put that in there like so and again move this into the position that we want so a good way to find that is to just minimize this slightly like so so you can still see it and then we're going to drag and drop a locker into our level like so and place it where we want so you can see we have a locker there in the bottom right we have a preview of this camera so if we move the camera this moves that camera preview as well so we can see what we're going to see when we're in the locker so i'm going to be using the values i found earlier and i found them by doing this so just moving it with that preview there so the values which i got were minus 10 on the x let me put back a little bit zero on the y and 78 on the zed so just move it back and up a little bit like so so if we compile we can check this again and that's the preview we're going to get there when we're inside the locker we're going to make this bigger again like so and that is the viewport all set up so now we can start moving onto the functionality of it and so the first step of that is to set up some variables so i'm going to deselect this and we're going to set up the door variables first select our locker door you can see that this is going to be the angle that we want it to be in when it is closed so we're gonna have the closed angle and that is going to be minus 90 as that's what it is on the z because we rotate it on the z like so so when it's closed it's minus 90. so let's hit plus variable in the bottom left down here name this close angle like so and change it from a boolean to a float compile and we can change the default value to minus 90 or whatever it is for you again it's just this value here as of right now i'm going to hit another plus variable again call this one open angle and we're going to open up our door to where we want it to be so again hit e and rotate it on the z and i want it to be about here so you can see that i moved out by 120 however because it started on minus 90 the value is actually 30. so it's gonna open 120 units to the unit of 30 on the set so i will set the close to be minus 90 and the open to be but again customize these to be perfect for you after this we're gonna go to the event graph like so and in here we want to delete these three events here what we're going to do next is we're going to create an action mapping so to do that we're going to edit project settings once it loads we should get input down here now i already have a few action mappings here they're just from previous tutorials but if you don't have these don't worry we hit the plus action mapping here name it whatever we like so i'm going to name either hide interact anything like that as you can see i already have them so i'll just get rid of that so i have hide i have interact you can choose whichever one i'm going to set the hide key to h interact to e again you can set these values to be whichever key value you'd like this is the button the player is going to press in order to hide and unhide it's going to be h e left mouse button f anything you want and the benefit of action mappings we can set up multiple keys we can set up keys from different consoles and we can also set up key bindings so once you've set that up we're going to close it back in the event graph here i'm going to right click and search the action mapping we just made so i named mine hide so we've got action event hide there underneath this we're going to right click on our box collision up in the top left add event add-on component begin overlap right click on it again add event add-on component end overlap we get those like that for the other actor of both of these i'm going to cast to our character which for me is the third person character i'm going to do that and put that into the other actors of both of these like so off this top one so begin overlap as to our person character i'm going to right click promote to variable and just call this character reference like that so we can use this later on then underneath this so in between the two we're going to right click get player controller out of this we're going to come out the return value and enable input that's not going in the target however that's going in the player controller we're going to plug that into the character reference there and we're going to right click and get a disable input player controller go to get player controller target itself plug it into the bottom cast there so this is what we should have so far when we enter the box cushion we're going to enable the player's input when we leave the box position we're going to disable it so this means when we are close enough to it we can't hide when we're not close enough we won't be able to hide in the locker so i'm going to hold down g and left click to get a gate which again is just solidifying this so we can only do it when we're close enough enter will be the press of our hide action mapping there open is enable input and close is disable input i'm going to make sure we leave start close ticked then what we're going to do now is we want to create a function and this function is going to be to hide and unhide the player we'll get in and out of the locker so we're going to hit the plus functions here over on the left hit plus function i'm going to name this one toggle hide like so out of this i'm going to hold down b left click to get a branch plugging that into there like that i'm going to hit the plus variable again to make a new one i'm going to call this is hiding question mark i'm going to change it to be a boolean so it's a true or false value i'll plug that into the condition there so what we do is when we press h it's going to see if we're already hiding if we are hiding we want to stop if we're not hiding we want to start hiding so off of true we're going to set is hiding to be false and off of false when the set is hiding to be true so this is how we are toggling it here like so what we want to do now is get our character reference there so drag and drop get character reference putting it in between these two sorry so we should take it's hiding there as well everest i didn't do that we need to take the set is hiding so now what we're going to do is offer false so when we start hiding we're going to come out of the character reference and we're going to set actor hidden in game plugging that in there like so i'm going to take new hidden i'm going to have new hidden as ticked so we are hiding the player and this is what is stopping the player from being seen by the ai and also by us so we're going to come out the character reference again i'm going to set actor enable collision i'm going to leave that unticked so we're going to be hiding the player and disabling their collision meaning that if the ai does run past the locker they're not going to collide with the player which is invisible so that'll work perfectly like so i'm just going to move this down a little bit to give it some more space after this i'm going to right click and get player controller at the return value of this i'm going to set view target with blend plugging that into the set actor enabled collision there the target is get player controller and the new view target is going to be get a reference to self so what this is doing is it's going to be moving the player's camera from their normal camera on the character itself to our camera we have in this locker so we're gonna be changing cameras from the player's camera to the camera we placed in the locker here so that will work perfectly like so so this is how we're gonna hide the player now we want to unhide when we press h again so what we can do is we can select set actor hidden in game set actor enable collision and set view target ctrl c ctrl v to duplicate it up here as it's essentially the same code we're just going to basically do the opposite of it so we're going to plug those in there the target for the sect actor hidden game is character reference same for enable collision and now the target for the set view target is also get player controller and also the new view target now is the character reference again so now we're changing the player's camera back to their normal camera in the character instead of the one in the locker and like i said we're doing the opposite so we're going to untick new hidden for set actor in the game and tick new actor enable collision on this top one here so this is going to be hiding the player and changing the camera this is unhiding the player and changing the camera back to the normal one what we should also do is set the blend time so the moment it's just going to snap between the cameras we want to smoothly blend it so to do that we're going to change the blend time i find good value for this to be 0.6 they're the ones which i typically use for these kind of things so it's what i'm going to be using as well and it's what i had in the start of the video so if you like that put this but obviously you can change it to be whatever you like customize it mess them up with it see what you like the most now we can compile save and that is how we hide and unhide the player so we can do is off the event graph we're going to drag and drop toggle hide put down to the exit of the gate there now if we compile and save this should work for just simply getting in and out of the locker we won't be able to move the camera just yet or have the door opening but this should be the basic part done so if we minimize we can see we still have that lock in here we hit play go first person walk up to it if i hit h i'm going to get in hit h we should get back out except we don't so let's have a look at why that happens now but as you saw we got in smoothly and it worked perfectly like so the camera changed and the player was hidden so let's go back into our blueprint here and see why that happened actually i do know why it's because we haven't finished this part yet actually because what happens is we disable the collision meaning this gate closes and we disable the input because we are leaving the box collision so later on we do re-enable that however i forgot that's just something i do later so this isn't actually done yet but if we did have that this would work going in and out so what we're going to do now is because we know that does work and we know why that didn't finish working yet it's just because we haven't finished the code so what we'll do now is we're going to actually open and close the door so i'm going to remove this toggle height there because we want to put something in front of it first so we're going to just underneath there and some space we're going to right click and add a timeline like so i'm going to call this one open close door t for timeline like so i'm going to double click this to open up and i'm going to set the length to be one second as i want it to take one second for the door to open and close again you can set this to be whatever you like next we're going to add a float track there and i'll just name this one door track like that i'm going to right click add key to curfload make sure you right click in the timeline i'm going to have the time zero value of zero so it's the very start right click add another key with time of 0.5 and a value of 1. so the door is open halfway through this timeline right click add key time 1 so at the end value of 0. so what's going to happen is when we start timeline the door is going to be closed the door will open and the door will close again as we're getting in we want to open the door get in and close the door so that will work perfectly and that works for getting in and out gonna compile close that timeline like so we'll also close toggle hide as we know that works now we're going to right click and get a lerp we're just going to get a normal up under float with the alpha as that door track float we have there as that is going to get the values between a and b a and b want to be our open and close angles so we're going to start at close so put that into a and b will be open now to actually open the door we want to drag and drop a reference to our locker door there so get lock a door out of this we're going to set relative rotation plugging that to the update of the timeline so it does it every single time the timeline updates or moves the frame we'll right-click new rotation split structure pin and plug the z into the return value there as we only want to be rotating the door on the z value and that is that done that's going to open and close our door what we can do is we can select this right click on it and collapse nodes this isn't necessary but it just looks a lot nicer and keeps it nice and organized i'm just going to name this one open door i'm gonna hit a plus input there new parameter i'm gonna name this one in i'm gonna change this to be an executable now we could add an out but it's not necessary to so i'm gonna do is move this up here out of the exit of the gate i'm going to hold down s left click to get a sequence plug in there and then one is going to go into this open door so the reason we're doing this is because we don't want to do this on the other part of code because this has a delay in it which is the timeline we want this to fire off separately so it does it at the same time so if we double click this again we can open it up now we can just connect this input to our in into the play from start of the timeline there and we don't need an output again but you can add one if you want we compile go back to our normal event graph now you can see this is going to work so the door will open and close so let's test that out to see if we need to change the value so we hit play we walk over press h it open and close perfectly like so so now we didn't need to change the value i think it just works either way so that's perfect so the door opens and closes like so and again you can change the time if you'd like so let's add the player to get back in again go back here into our blueprint what we can do is off of then one then zero sorry we can again toggle hide like so now we're going to hold down d left click to get a delay i'm going to place it just a little bit over here as later on we're going to add something else in here the delay i'll leave as 0.2 out of completed i'm going to come all the way back to the start we have enable input there i'll just double click these nodes to get root loads like so and this will work perfectly now let me just do this as well and this isn't necessary i just like to keep it nice and neat and organized so now this should work so the player can get in and out the reason we do this again is because when we disable the collision we need to just make sure that we re-enable the input and go back into the gate again so compile minimize let's see if this part works go up to it press h door opened closed we got in press h and get in and out again so this works perfectly so what i might do is increase the time that it takes for the camera to go in so you see we're going in quite fast so i'm going to do is i'm just going to change that so we go back into the blueprint double click toggle hide and we just increase this blend time here so what i'll do is i might just up it to 0.8 so it takes one second for the door to open and close so i'm going to set this to be 0.8 to get in and out compile and let's see what this one looks like and again it's just up to you to change the values and get it perfect for what you want so i think that's a lot better so we kind of open and close with the door like so and of course you can also just make it so the door takes longer to open but i like this a lot better now so i think that works great so now the final thing to do is set up so we can move the camera roller in there so the basic functionality we've got set up working perfectly now i'm just going to make it so we can actually move the camera so setting up the movement of the camera is very simple as well so what i'm going to do is i'm just going to select this hit c to comment it first of all i'm just going to name this one get in and out of locker like that just so we know what it does easily like so and underneath this i'm going to scroll down to get some empty space i'm just going to right click i'm going to get the look up input axis there so the axis event input lookup then i'm going to right click and get the turn as well so axis events turn i'll do the lookup first so we're going to hold down b left let's get a branch the condition of is hiding i'm going to do is we're going to get the character reference again out of this we're going to add controller pitch input it's looking up is on the pitch we'll plug that into the false there with the value as the axis value there so we're going to do is essentially if we walk into the box collision we're still going to be moving the camera like we normally should for the player and as we get into the locker then it will change but otherwise it's going to stay normal so now to change it what we're going to do is we're going to hit the plus variable again this one i'm going to name pitch i'm going to change it to be a float and we can also make the yaw as well for later on so what we're going to do is over here we're going to drag and drop the pitch get pitch i'm going to get a float plus a float and we're going to be adding the axis value to it let me just double click this again to get some root nodes to keep it nice and organized so we're going to do is we're going to add the pitch to the axis value so this is just going to calculate the correct pitch for us when we want to move so then out of this we're going to get a clamp with a clamp of float and that goes into the value and this is because we want to keep the pitch between certain angles so you saw at the start i couldn't move too far left or right or up or down because it pitches up and down so that's what we're doing right now and so that's just because we don't want the player to be able to do a full 360 in there or break the camera or anything like that as it's a locker you can't normally do that it's quite cramped space in there obviously if you do then you can just put it as zero and 360. so they spin all the way around and look all the way up and whatever whatever you like but i don't want to do that so i'm going to change this so i'm going to set the minimum value as -40 and the maximum as 20. now again i did the same method to get these values so these are just ones which i found to be nice but what we can do to get them to minimize it select the locker go to the viewport and just move the camera between these values so we move on the pitch first which is the y so up and down so i want it to be 20 which is all the way up which is there so 30 is a bit too high for me so i'm going to have it a maximum of 20 and a minimum so all the way down i want to be minus 40 so i can look all the way down there when it's 30 or any other value but again move it here and get the perfect values for you so i want it to be -40 and 20. again get them ones which you want out of the return value of this we're going to set the pitch plugging that into the true of the branch there what i might do is just move this down a bit like that so what's going to happen now is we're going to be moving the pitch between these values that we want and setting it so that whenever we move the mouse we're moving the pitch so we're basically creating this add controller input here but we're just making it ourselves because we're not actually adding controller input we should be moving the camera so we just have to simulate it like this one other thing we can do is out of pitch i'm going to get a multiply so it floats multiplied by a float i'm going to multiply it by minus one and that's just because otherwise if we don't do that then the pitch is going to be inverted which obviously we don't want i mean you might do something you don't need to have that but i don't really want that and we'll come back to this later on but now let's set up the yaw so we've done the pitch up and down now let's do the yaw left and right so what we can do is we can basically copy and paste this again and just change certain values so we'll select the is hiding the branch all of this stuff copy so ctrl c ctrl v to paste put it back down here like so then plug the axis value in there and back in there where they should be target into the character reference like so again i'm just going to rewrite these to keep them organized and what we can do is we can just drag and drop our your variable onto the pitch there to change it so now we're getting the yaw added to that we'll do the same here so we set the yaw and we don't need the multiplication there as this one isn't inverted and then we can change the clamp values as well so ones which i found to be quite good were minus 60 and 60. again customize this to get perfect for you we'll do the same method exactly the same so select the camera change it on the yaw which is the said between these so i want 60 to be there and minus 60 which is there so these are values which i want again pick the ones which are best for you i want minus 60 and 60. so now we want to actually do something with these values so we set the pitch and the yaw and i want to do something with it so that's very simple what i'm going to do is we're going to right click and make rotator as we want to rotate the camera the your which is said we'll go into the you're there the y which is pitch will go into there so now we're setting the pitch and you're into a rotator and then we'll actually rotate the camera so we're going to get the camera there out of this we're going to set relative rotation just like we did with the door with the new rotation as this make rotator return value there and now we want to loop this so we're always moving so we're always moving the camera when we're in the locker so we're going to right click add a custom event and we're going to name this one move camera after this we're going to hold down b left click to get a branch with the condition of is hiding and that's because we only want to be moving the camera if we're hiding so this is what is going to continue or break the loop true we're going to set relative rotation so when we stop hiding the loop will break which is what we want after the rotation we're going to hold down d left click to get a delay with the duration as 0.001 so it's very small so we don't notice it off completed we're going to move camera so call function move camera like so which is why if you name this custom event so this is essentially simulating event tick however it's more efficient because there's only firing off when we need it to so this should work perfectly so i can select all this hit c to comment again and i'll name this one move camera so again we're just basically simulating this add controller input for both the pitch and the yaw to get perfect for what we want and we're moving the camera according to those values now we need to call this as well when we actually get into the locker let's go back up here you see we left some space between toggle hide and the delay so we're going to come out of toggle hide and call function move camera you can put that in there and this should now work perfectly for us so we compile save minimize and let's hit play to test this out so we'll walk over go to the locker press h we'll get in the door opens and closes as we get in and we can move the camera around like so between these values which we set so we can look up right left down between the values which we wanted so this has worked perfectly and press h and get back out again like so and if i place multiplying so i just hold down alt left click and drag to duplicate these we can see that this works perfectly with all of them rotate we get in and we can move around and get out again like so also sorry one thing as i was doing the outro there you may have noticed something went a bit odd if i walk in here we can look up and down but we can't look left or right reason being when we duplicate this code here input axis turn we left it as add controller pitch input when we should have changed it to add controller your input like so and now this should work perfectly for us so i'll get back to the outro if you notice that this is why this is the fix for it so if you see that in the outro don't worry about it and also make sure to plug the value into the axis value there like so so i think that'll be this video is we've done everything we want to do we set up a locker in which we can press h to get in and out of and it hides the player so we are actually hiding in there so the ai won't be able to see us as well we get in out once we're in it we can move the camera around between values which we set as well and we can use these as many times as we want on any rotation we want as well so thanks so much for watching i hope you enjoyed and i hope you found it helpful and if you did make sure to like subscribe down below thanks so much for watching and i'll see in the next one [Music] you
Info
Channel: Matt Aspland
Views: 29,435
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, games design, ue5, unreal engine 5, horror, hide, locker, in, ai, hide player, ue4 hide in locker, ue4 locker, ue4 hide from ai, hide in locker, cupboard, wardrobe, game, mechanic, ue4 horror, granny, part 2, chapter 2, horror game, from, away, enemy, hide from enemy, hide under bed, hiding, object, inside, under, the, camera, look, ue4 hide, ue4 ai, ue4 enemy ai, hide from ai, see
Id: gHJ4pHlqAzQ
Channel Id: undefined
Length: 26min 43sec (1603 seconds)
Published: Tue Feb 09 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.