How To Create A Prone System - 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 set up a prone system for your character so we're going to do if i hit play right now i'll be able to show you so we're in the game and you can see that we just have our character here if we press z or whatever button you choose we're going to go down into our prone position like this and we can move around like that and it'll be a lot slower and we have our animation like this if we press that again we're going to get back up and also the collision does work on this so we can climb underneath or crawl underneath sorry smaller objects or lower down objects like this the collision works and if we press said to get back up while we're under here we can't so we can only get back up from our prone position when we can actually stand up like now so that's to work perfectly so i'll show you how to do this and this is fully customizable you can use your own animations and all of this good stuff like that so i'll show you how to do this now so our first step is going to be to actually create it so we can prone so basically when the player presses a button we're gonna be able to go into our prone position so to do that we're gonna open our character blueprint so for me that's content third person bp blueprints third person character but for you this could be first third whatever you've named it once we're in here we're gonna find some space and then we're gonna go up to edit up in the top left project settings once this is loaded we're gonna go down to input down here and we're gonna create an action mapping so hit the plus action mapping there i'm just gonna call this one prone and the reason we're doing this is so we can add multiple buttons and we can have different buttons for different consoles and also set up key bindings so under none here i'm just going to set this to be zed example prone is most commonly across games but you can choose this to be whatever you like so i'm just going to close that and then back in the event graph here i'll right click i'm going to search for prone and get that action mapping there out of this i'm going to hold down b left click and get a branch plug that into pressed there for the condition what i'm going to do is hit a plus variable to make a new one i'm going to call this one prone question mark and like i say that's gonna be the condition so this is basically if we are pruning then it's not gonna prone if we're not pruning we will prone so this is just instead of using a flip-flop as sometimes flip-flops can get out of sync and out-of-date this just means it won't so out of true what we're going to do is we're going to drag prone onto there to set and we're going to set that to false so if we press z and we are pruning we want to stop as the player wants to then get back up again so we will set that to false out of this we're going to set another one so hit plus variable again and this one i'm going to call getting up question mark and i'm going to set that one to true as the player is getting up they're standing up and we're doing this so we can play an animation later on as you saw we had a smooth transition for an animation going down and an animation for going up this is how we're doing that then off of false what we want to do is set prone to be true so if we're not pruning we then are and instead of getting up to be false as we're not getting up we're going down so actually make sure you tick the top one there i didn't do that so make sure you do tick it so it is true that's for the top one so it should look like this then out of the true so set getting up equals true we're going to hold down d left click to get a delay and i'm going to set this delay to be 1.3 seconds now i'm doing that as that is how long my animation is but if you're using different animations set this to be the correct speed and time for you then after this what i want to do is just set our movement speed so i'm going to get the character movement and drag out of that i'm just going to set max walk speed and by the way the character movement is up in the top left you can just drag and drop it in then set max walk speed plug that to the completed of the delay there and i'm going to set this back to my default walking speed which is 600 so by default they're all 600 but if you change this make sure to set it to that again so i'm going to come out the couch movement again and once again set max walk speed this one i'm just going to plug in to the false so set getting up is false and this one is going to be our walking speed when we are proned so lying on the floor so i want this to be 50. so when we are crawling around we're going to be moving at 50 speed instead so that is essentially that part done so we're going to build up on this later but this is the basic part done so that the animation knows we want to go to prone so what i'm also going to do is i want to make it so we can't jump when we're pruning as obviously if you're lying on the floor you don't be able to jump so to do that i'm going to go find the jump code which you should have by default yours will probably be up here under mouse input to the left of movement input but just move it down here select the jump and stop jumping move those out to give you some space hold down b left click to get a branch and plug that into the pressed and out false go into jump like so leave stop jumping as it is and the condition of this is going to be prone so basically if the player wants to jump if they aren't pruning they can jump if they are proning then they can't jump so nothing's going to happen i'll just double click that to get a root node like so and that should now work perfectly like that so it's just a nice little feature that we can add something i'm going to compile save minimize that is that's all we need to do in here for the moment and what we're going to do is we're going to set up the animations so if we go to content and then as i'm doing this in the third person character i'm going to mannequin animations third person and mbp obviously if you have your own animation blueprint put that in there but i'm doing this in the default one so what we're going to do is we're going to go over to the event graph here and then we're going to come up find some space right click get an event blueprint beginplay like so out of this i'm going to cast to my character so it's cast to third person character like so the object being get player character so get player character like that as third person character i'm going to right click on it promote a variable and call this one character reference like so so we're just creating a reference to our character so we can use it later on and i'll compile that and then i'll go down to the end of this code so for me that is where it's setting the speed i'm going to go down to there just so we can come off of event blueprint update animation so basically we want to come off of that so i'm going to go to the end of the code down here i'm going to hold down d left click to get a delay plug that into there like so and i'm just going to set this to be very short so i'm going to set this to be 0.05 seconds alpha completed i'm going to drag and drop a reference to our character reference there so get character ref and i'm going to get prone so get prone question mark right click the return value promote your variable and just call this one prone question mark as well plug that into the delay and then now the character reference again i'm going to get getting up question mark and do the same thing right click promote to variable call it getting up the reason we're doing this is just so that we can then use these variables and these booleans in this animation blueprint as well so we compile and save and that is that part done so now we're going to go back to our state machine which is here so jump start and then go back to default like so from here what we're going to do is create two more states which is going to be for our proning so i'm going to come up with the idle run so make sure that you set this up to be how you want so you come out of these states you want to be able to prone from so i only want to be able to prone from idle run not from jumping so i'm going to come out of that state there i'm going to then add state and i'll call this one prone transition so this is where we're going to have the animation going down and going up then drag an arrow from that back to the idle run state like so then we're going to drag out this state again and we're going to add another state and this one will just be called prone and then we'll drag from that back to the prone transition like that then what we're going to do is double click our prone transition to open this one up and we're going to come out of the result here and we're going to simply blend poses by ball like this meaning that we can have two different animations in here and it will only play one depending on a boolean value which is this getting up variable we made earlier so the active value will be getting up and we made earlier so dragon dropper in there for that and so true is basically if we are standing up so if we are standing up we obviously want to get prone to stand so put that into the true there like that and if it's false so we're not standing up we're going down we'll get stand to prone like that in here you can change the animation blends but we don't need to do that as we're not actually going to be going from these two together so that doesn't matter also these animations i will link in the description down below so these are just ones which i got from the marketplace for an animation starter pack and also from miximo but i've just retargeted them to work for the third person character or the uefa mannequin sorry so i'll be linking notes in the description down below i'll probably put something that started this video as well as i forgot to mention it so that is that part done if you get any compiler errors or warnings that's just because we haven't finished setting up yet so once you've done that go back to the default so we go back to here like so and then we're going to create the transitions so being able to go from idle run to the prone transition so it's these transitional nodes here so i'm going to double click these two arrows here so it's idle run to prone transition double click that to open it up like so what this means is this is going to allow us to go from the idle run to our prone transition so what i want to do is just get is prone so get prone like that equal equal boolean and tick that so it's true so if prone is true so if we are proning we want to go into this transition go back to default then click the one to the left of that so prone transition to idle run this one's gonna be slightly different as we want this one to be when an animation has finished so i'm going to do is i'm going to right click get time remaining ratio for prone to stand like that so the time remaining on our understand animation because obviously this is going back to standing so we want it to be from our prone to stand position at the return value one can do is get a less than float so a float is less than a float inside this i'm going to put it as 0.2 return value goes in there so basically when the animation has less than 0.2 seconds left what it's going to do is then go into this and transition back to the idle run blend space animation so we go back to default now we're going to do the transitions from pro and transition to prone so what these transitional nodes do is essentially it allows us to transition from these states so i'm going to double click the prone transition to prone this one is again going to be the same time remaining ratio thing that we did earlier so right click time remaining ratio this time it's stand to prone as we are going down to prone instead of up to stand return value is again going to be a float it's less than a float and it's going to be less than 0.2 seconds like that so it's the exact same thing before just the other way around so we go back to default now all we need to do is set up the animation for our prone so what this is going to be is is going to be a blend space so we compile save this this is the only thing we have left to do so we're going to minimize this and we'll right click in our animations folder here go to animation and then we're going to get a blend space 1d like that target it to your skeleton so for me that's the ue4 mannequin skeleton i'm going to call this one prone bs for blend space and open that up straight away like that in here we're just going to drag in our prone idle so drag that in and put it all the way up to the left like so and we're going to get our prone forward and put that in the middle like that so now if you hold down left shift and move your mouse you can move between these two animations so you see all the way over here we're idle and then when we're here we're moving forward like so so obviously if you have a faster prone so you're basically sprinting you can put all the way over the far right here but this is gonna be good for me so then up over the left under the axis settings we're gonna get horizontal axes change the name from non to speed as that's what this is minimum i'll leave it zero maximum i'll leave it a hundred so basically when the speed is at 50 or above we're gonna be moving so actually i'll move that down to this first line here so if it's at 25 or above we're moving forward if it's below that we're idle or transitioning back to idle so also the interpolation time i'm gonna put a 0.5 and that's basically the transition time between these two animations so it doesn't just snap between them so that is all we need to do in the blend space that is it's set up so we can save and close that now back in our animation blueprint we should have this prone blend space here let's drag and drop that in plug that into the result there the speed there we can just get our speed so get speed like so which you should have anyway because in the third person one it's there automatically and you should also have it for making your idle walk run blend space as well so you can just use the same thing so we can compile save we're still getting one warning so that's because the prone to prone transition will never be taken so if we open that up we can see that we didn't actually finish that one off so we did prime transition to prone but not prone to prone transition so let's double click that to open it up and so this one just wants to be get prone again equal equal boolean and leave it as unticked so if it's false so if we aren't prone we want to go back to standing up so through all these transitions so for compile this is now the blueprint done so this is basically the basic part of prone done so in compile save minimize this if we hit play to test it we should see that this will actually work so if we hit z you can see that we are proned if we hit z again you can see we're getting up and that works perfectly we have the animations as well and also if we are prone we can't jump if we want to but you'll notice that i have this capsule collision box visible and so i've got that visible so we can see that it hasn't actually gone down with the player so what's gonna happen is if we try to prune or crawl underneath something we're still gonna get blocked as our collision is still up there like that so we can't actually go through so obviously that's not what we want so let's fix that now so i'm going to do is we're going to come out of this i'm going to go back to our third person character blueprint so third person bp blueprints third person character or again first third or whatever you've named it and in here we're going to go back to this prone code that we made earlier like i said that was just basic and we're going to come back to it this is where we're coming back to it so we're going to change this up a little bit so what we want to do before this delay here we just want to move this out a bit so just move that out and we're going to hold down s left click get a sequence then 0 is going to go into the delay like so i'll leave that like that for the moment as we're going to mess about with that in a minute then over here after this i'm going to right click i'm going to add a timeline so add timeline like so and i'm just going to call this one prone transition as well just so we can keep this nice and smooth so i'll put that there play from start it's going to go into the bottom one here so set max walk speed to 50 we'll go and play from start and then this sequence then one will go into reverse from end like so i'm going to double click these to add some rewr nodes to make it look a bit more organized like so so what this timer is going to do is just smoothly transition from my different values so then what we want to do is actually move our meshes location so the player and also change the size of our capsule component so essentially what we want to do is move our player like this and change the size of our component like this so that is going to work with the collision so we go back to our event graph here out of update we're going to drag and drop a reference to our mesh so drag and drop the mesh like that and we're going to set relative location plug that to update like so and then after this we're going to drag and drop a reference to our capsule component come out of that and we're going to set capsule size like so plug that into the set relative location like that so now we're going to smoothly update these so we've done that and what we're going to do is double click on our timeline to open it up the length is again how long you want this to happen so i want this to be the 1.3 seconds which i've got earlier because that's how long my animation is so that once you set the length we're going to add a float track i'm just going to call this one prone transition again or prone track it doesn't really matter what you name it but then in here we're going to right click add a key with the time being 0 value being 0 right click add another key time being 1.3 so your full length value being one we hit these two arrows here we can then fit this to be perfect like that but that's what we need to do in the timeline so we can just close that like so and you can see we have this track here which we can then mess about with this so we're going to come out of this and we're going to get a lerp vector like so the return value of that is going to go into the new location of the set relative location like so i'll just move this over to give us a bit more space to keep it looking a bit more nicer and then we're going to come out of the prone track again get a larp float so just a normal up with the return value of this going into the in radius there come out the prime track again getting another larp just a normal one the return value going in half radius of the set capsule size like so and it's not going to go into a sorry so prone track won't be an a it will be an alpha like that as it's going to get the position between the values of a and b which we're going to make in a minute so like i say this is just going to smoothly transition between a and b to get our two different sizes and positions that you want without it just stuttering and lagging and looking really bad so again i'm just going to clean this up a little bit by again double clicking on these wires to get the rewrote nodes like so so once you've done that we're going to make our variables to go into the a and b values so i already have the values that i want but i'll show you how i got them as well as i got these when i was just making this code earlier so the first one we're going to make is we're going to hit the plus variable i'm going to call this one start position and this is going to go from a boolean to a vector so this is going to be a on our lap vector here as i say this is going to be the start position of our player so we compile so we can change the default value of that and all we're going to do to get this is we're going to select our mesh that will go to the viewport as well so we see everything and it's going to be this position so it's going to be our starting position so the default location our player is in which is obviously this so x is 0 y is this one so we're going to select it hit ctrl c to copy going back into our start position ctrl v to paste it into our y select the mesh again and then change the z which is minus 97 so i put minus 97 into the z like so and then we're gonna do is hit plus variable again keeping this one as a vector again this one is going to be called prone position and this is basically where we want the player to be when they're proning so i kept the y the same so that should already be on my clipboard so i can hit ctrl v to put the y in there and the z i got is minus 27 the reason i got minus 27 is i move the player up to minus 27 so what we do is select the mesh use animation asset keep it as prone idle so i can see what we're going to look like when we're pruning and if i move this all the way up to minus 27 you can see we're going to be there now you might wonder why we're going to be there but we'll figure that one out in a minute so put it as -27 for you with a moment as i imagine you'll probably have the same or at least very similar values but if you've changed what your character looks like they might be slightly different so then the next variable we're going to make is hit plus variable again this one is going to be called stand radius this one is going to go from a vector to a float this time i'm going to hit compile so we can change the value sand radius what we're gonna do is just select our capsule component here and get the capsule radius which is 42. so if we select our standard edges again and just put 42 in here like so hit compile the next one we're going to make is prone size so hit plus variable this one is going to be stand height so get stand height like so which again if we just select the capture component it's going to be the capsule half height which is 96. so we select our variable compile and just put 96 in there these will probably be the same for you if you haven't changed it but again i'm showing you how to get these and after this if we hit plus variable again we're going to now make prone size so you get prone size like so compile so we can change it and i'm going to set this one to be 30 as that's what i got earlier so if we then select the capsule component change the capsule radius to be 30 and then change the half height to also be 30 when you see we get this little ball here which is also where i got the value for how high i want the player to move so you then move your mesh up to be perfectly in sync in line with this like so it's like say minus minus 27 so get that to look perfect and work perfectly for you and that is all of the variables we need to make so we can then just put all these back to normal so we have a start position which was minus 97 so put minus 97 on the zed change it back to the blueprint like so capsule component was for me 96 and 42. again set this back to the default you had for you and we're talking about hitting the game like that so in compile go back to the event graph so now we're going to put these in so start position we're going to a of the alert vector like that prone position we're going to b so it's going to go from the start position to our prone position like that then at the second lap we're going to get the stand radius in a and then the prone size in b so we go from our standard radius to prone size and then the final up is going to be stand height to prone size like so and again i'll just move these to make it look a little bit nicer like so so now that's going to smoothly transition between these values as well so we compile save we should be able to see this as well so if we hit play we can see our capture component if you can't you don't need to anyway as you wouldn't want to but just select it and then untick hidden game there so now we can see if we press z it's going to smoothly transition between those so the capture component is now all the way down and the player is also there as well and if we go up it will do that perfectly as well and this is just so that it doesn't jump between these two values as we need to change these values to get the collision to work so if we go back over here we hit z we can now prone and we can actually go and crawl underneath these objects like so with our collision working but if we're underneath it and press set what's going to happen is we're just going to stand up in here which obviously we don't want as we can then get stuck very easily or it just doesn't look good and it glitches out so we're going to solve that now so we come out of this and go back to our third passing character blueprint here we're going to do is we're just going to come back over here select all of this so select everything after the branch and just move it out so move it all out to give us a nice bit of space here i'm just going to zoom in to this branch here out if they true what we're going to do is we're going to get a line trace by channel so line trace by channel like that and then we're going to hold down b left click to get a branch plug that into there return value as a condition and we're going to go out false and go into the rest of the code like so so basically we come out false as if this doesn't hit an object we're not going to move we are going to move sorry so if this does hit an object nothing will happen if it doesn't we're going to stand up but we need to actually be able to draw this line as well so it knows where to hit so to do that what we're going to do is just going to simply get actor location and that is just going to be the start so it's going to start drawing this line from the player then we're going to right click get actor rotation come out of the return value i'm going to get the up vector so this is going to go straight up above the player so obviously if there is something above them they can't stand up out of the return value of that we're going to get a multiply so a vector times a float and this is how long you want it to be so this is the length of the line which i found 180 was quite good that was just reached just above the player in their standing position so i messed him up with this to get it perfect for you and you can see how long it's going to be is if you draw debug type for duration like so you can see the red line and see where it's going to go then out of get actual rotation again what we're going to do is going to get a plus sorry vector plus a vector the bottom value as that multiplication and plug that to the end and that's just to keep it a straight line like so and that is all that done so i'm just going to double click this to get rewritten nodes but now this is going to prevent us from standing up if we are underneath something as if we are underneath something it's not going to do anything but if we're not it will stand up like so so now if we compile minimize hit play to test this if you press said we go down if you press that again you see we get that red line and that's just above the player's height like so which is where you'd want it to be so if we press set we can transition in we can move underneath this object here we press that again you can see it's hitting the roof so it's going up and it's hitting the roof there and we can't stand up but as soon as we get out of here we're going to stand up straight away like that which works perfectly then just to make this look a little bit nicer what i'm gonna do is get four duration change that to none so we don't have the line select our capture component and put hidden so we don't see that in game either and now this should look perfect so we hit play you see we don't get any of those so i think the update for this video is we've done everything we wanted to do we've created a prone system so if we press z or any button you want we have a smooth transition down into our prone if we press set we can get a smooth transition back up and when we're also prone we walk slower like so and we've also set up so the collision works so we can crawl underneath objects like this and also when we're underneath these objects we can't get back up as obviously will glitch through the wall and the roof on the floor like that but as soon as we get out of these objects we can stand up again like so so that works perfectly 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 so thanks so much for watching and i'll see in the next one [Music] you
Info
Channel: Matt Aspland
Views: 26,831
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, third person, first person, fps, tps, prone, system, crawl, climb, shooter, stand up, up, down, stand, transition, smooth, smoothly, ue4 prone, collision, ue4 prone collision, basic, advanced, quick, easy, pubg, hide, underneath, through, objects, cant, if, under, lie down, lye, flat, capsule component, horizontal
Id: i5Ql5dBlOas
Channel Id: undefined
Length: 24min 19sec (1459 seconds)
Published: Sun Nov 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.