How To Crouch In Unreal Engine 5.1+ (Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome back to another Unreal Engine 5 tutorial in today's video we're getting over is how to set up crouching with animations using the new enhanced input system so essentially unrelation 5.1 and Beyond this is how you crouch some hit play and show you what it is we're going to make today so I could walk around like normal and if I had to hold Ctrl or C you see we're going to go down and Crouch with an animation going down as well and then we can walk about and then also if I were to then let go of control or C we're going to get back up using an animation as well so this is what we're going over and creating today as you can see we have this nice Crouch system using the new enhanced input system the animations might not look perfect that's just because I very quickly got some free ones from mixmo you can also use your own ones to make them look a lot better like I say this only going over in creating today so without further Ado let me delete this code and I'll show you how I've done it so the first thing we want to do is we want to actually create our input to be able to crouch so to do that I'm going to go to control space in our content browser then for me my inputs are in third person input actions but just do this wherever you have your interactions then I'm going to right click go to input go to input action and I'm going to Simply name this IA underscore Crouch and let's open this up straight away and you should be able to leave everything by default as you see here so save and close this next we need to add this into our input mapping context so let's go to control space again and find where that is so for me that's IMC underscore default if you don't have this setup what you can do is follow my tutorial Linked In the description down below and on screen now to set up the enhanced input system but if you have got it done what we can do is simply add a mapping on here setting this to be our IA Crouch and then set this to the Keys we want for me I want left control and I also want C so those are the two buttons I have so you can use either one to be able to crouch we don't need to set anything else up on here that is it so we will once again save and close that next we're going to actually set up using this action to be able to crouch so to do that we're going to go to our character blueprint so let's go back to our content browser third person blueprints BP third person character or whatever it is that you've named it the first thing we need to do in here is make sure that the player can actually Crouch as by default they can't so what we're going to do is Select our character movement component search for Crouch and make sure that we have ticked can Crouch Again by default you can't Crouch so you just want to make sure that is ticked and enabled then we can also do is change the half height and also the speed of Crouch movement as well if you wanted to however I'm going to leave those as default as for me they are perfect so let's compile and save that now we've enabled crouching all we need to do is actually call it that is very simple what we're going to do is right click and search for IA underscore Crouch or whatever it is that your enhanced action event is called so just get that then what we're going to do is off of Started we're going to do Crouch and it should be a function that you already have and then off of completed we're going to Simply uncrouch so these are functions already created for us by default inside of the engine all we're going to be doing is calling them as you can see here so for me this is on hold so when I press down Ctrl or C we're going to be crouching and when I let it go we're going to be uncrouching if you wanted to be on toggle instead of hold all you can do is out of started get a flip-flop and then a we're going to crouch and B we're going to uncrouch and uncrouch does not come out completed it would look something like this instead however I don't want it toggle I want to behold so I'm going to leave it as it was earlier like so let's select all this hit C to comment it and I'll just simply name this Crouch we'll compile and save and that is all we need to do the character is now going to be crouching so we can close this however all we're going to do is if we hit play you can see that if we hold Ctrl or C the camera is moving to signify we are crouching and the Collision will also be changing so the player is actually crouching right now however there's obviously no animation as we've not set up so let's do that now so what we're going to do is open up our animation blueprint now for me this is going to be into content characters mannequins animations and then I'm doing an ABP Manny because this is going to be the parent so if I go into ABP Quinn you see it's parented too many obviously just use the animation blueprint you are using for your character so it might look slightly different to you but everything I'm going to do is the exact same in here what we need to do is just find out if the player is actually crouching or not so you can see what I have here is update animation we're seeing if we have the character the character here is simply just a cast what I'm going to do is out of the movement component which I have here so if you don't have the movement components come out of the reference of your character and simply get character movement then get the movement components out of the movement components all we're going to do is search for is crouching and you see we have this as a Boolean already here so this is going to be using the function we've just used to see if we we are or aren't crouching when they're going to right click the return value promote it to variable naming this simply is crouching so now we know inside of our animation blueprint if the player is or isn't crouching we obviously want to just make sure we connect this up into our execution as well so it is going to be set and let's just comment this set is crouching as simple as that so we'll compile and save that like so next what we want to do is start setting up some of the animations so I'm going to go into my Allen graph here for you this might look like this and then I've just connected it straight into here as that's what I want and I've gone into my state machine I'm going to drag out of the idle State and add a new state naming this Crouch transition and I want to drag it from Craft transition back into idle like so and then I'm going to drag out of Crouch transition add another state naming this one Crouch and I'll go back into Crouch transition as well so we can go from idle to crouch transition back to idle and crowd transition to crouch back to crouch transition now what you can also do is add these onto walk run like this as well so that means you can be idle or walking and running to be able to go in between all of these like so and I'll move this over like that just so it's a little bit more centralized then we need to actually start setting up the transitions between these so to go from idle or walk around into Crouch transition so essentially to enter the Crouch transition we want to make sure the player is crouching so we'll double click that line here idle to crouch transition and simply we can just get its crouching connect the Boolean in there so if this is true then that means we can enter the transition which means we will so we'll enter this state here and we'll do the same for walk run to crouch transition as well nice and simple then to go back from Crouch transition to idle or to walk run what we want to do is simply just select it don't double click it click it once and we want to take automatic rule based on sequence player in state so tick that for both of these like so what I'm also going to do is set the duration from 0.2 to 0.5 just to make it look a little bit nicer and also it makes it just work better as well as sometimes it might not work fully as it doesn't have enough time to transition out of it but what this will do is essentially when this animation in this state has finished playing it will then enter this transition to then go into the other state so that means we don't need to do the Maths for figuring out when to end this transition it would just be once the animation has ended it will then exit and go into the other state which we want so that is perfect as that means we want to do the same leaving the Crouch transition going the other way as well so anything leaving Crouch transition is going to be automatic rule based on sequence player and state so cross transition to crouch will be the same and then Crouch to crouch Transit we'll double click that to open it up and this wants to be is crouching not Boolean so if we are not crouching anymore the player has stopped crouching we want to then go back into the Crouch transition to get back up to stop crouching that isn't perfect gonna go between all of our different states here however we don't have any animations in these states so let's set that up now as well let's double click Crouch transition and set that one up first as we're going to have two different animations in this one state what we want to do is we want to right click and get a blend poses by bull node so what it's going to do is it's going to choose which animation to play based upon a Boolean value that Boolean obviously being is crouching so let's connect this up to the result there and we'll get is crouching and connect that into active value so depending on what this Boolean value is is dependent what animation it's going to play so if is crouching is true it'll play the true pose so if is crouching is true that means we are now going into the Crouch position so what we're going to do is let's search for crouch in our animations here and we want to have the stand to crouch so stand to crouch here as if we are crouching it means we're going into the Crouch position if this is false that means we are standing up we're no longer crouching so we want to crouch to stand like so and that means we're going to have these two different animations playing at different times within the same state so we don't need to make a different state for each one so we don't need a state for Crouch to stand and want to stand to crouch we can have it in the same one here making it nice and efficient and just a lot better for us says compile and save that and that will work perfectly like so now all we need to do is the crouching so what I'm going to do in here is I'm going to be doing a blend space so let's go and create that now I already have one here you can see so I would delete that in a second so what I'm going to do is just go to where I want my animations to be which I believe I just put into this animations folder here so these are all the animations I'm using again I got these off from mixmo.com which I'll leave a link to in the description down below so let's delete this and I'll recreate it in a moment so let's now right click go to animation go to Legacy and create blend space 1D setting this to the skeleton we want wish for me is SK mannequin and I'm going to Simply name this abs for animation blend space underscore Crouch like so and we'll open it up straight away in here we're going to change the name of the horizontal axis to be speed the minimum axis value being zero maximum axis value being the maximum speed the player can move when walking which for me is 300 it is 300 by default so unless you've changed it keep it at 300 and you can see that by searching for crouch in the character movement of your player blueprint which I showed you earlier as well great divisions we're going to set to two and then we're also going to take snap to grid now we can search for Crouch once again and what I want to do is get Crouch Idol all the way on the left over here and then we'll get Crouch walking all the way on the right if you hold left control you can move the preview and see that when we're not moving so we're at zero speed we're going to have the idle and then when we are moving we have 300 speed we're going to be walking like this so this is what it's going to look like it is as simple as that all this is going to do is just simply transition between these two animations like so based upon the speed input we give it so we'll save and we can close that and back our animation blueprint we can drag in this ABS Crouch or the animation blueprint whatever it is that you named it in here like so and then we'll drag out speed and we will simply get speed for me it's called get ground speed but for you I imagine it's probably just called speed so we'll compile and save that if you don't have a speed variable then you'd probably want to set up your own animation blueprint which you can see how to do using the video on screen now and in the link in the description down below but if we go back to our Locomotion State machine you can see this is now all going to be working perfectly for us let's close this and hit play to test this out If We Hold Ctrl we have the animation going down and we're now Crouch idle and if we start walking we're going to have the Crouch walking animation like so as well and if we were to stop release Crouch we have the animation going up as well and this will also work for moving too as we've set it up for all of those as you can see perfectly here so I think that'll be it for this video as we've done everything we want to do what we've done is we've set up a crouching system using the new enhanced input system in Unreal Engine 5.1 and Beyond in which we can Crouch going down an animation and move about and also Crouch to stand with an animation like so so thank you so much for watching this video I hope you enjoyed that and hope found it helpful and if you did please do make sure to like And subscribe down below so thanks so much for watching and I'll see you in the next one foreign [Music]
Info
Channel: Matt Aspland
Views: 35,208
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, blender, unity, games design, ue5, unreal engine 5, unreal engine 5 tutorial, ue5 tutorial, crouch, enhanced input system, 5.1, 3d modelling, graphic designer, crouching, left, ctrl, control, controle, toggle, hold, anim, animations, bp, blueprint, ue5 crouch, ue5 crouching, system, easy, quick, easily, on, button, press, input, action, animation, anims, transition, anim bp, mixamo
Id: NmCKwbPx-Cg
Channel Id: undefined
Length: 12min 47sec (767 seconds)
Published: Fri Apr 14 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.