How To Crouch | With Animations - Unreal Engine Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome back to another invention full tutorial in today's video i'm going to be going over how to set up crouching so we're simply just going to set up crouching with animations from going stand to crouch crouch idle crouch moving and crouch to standing as well and this will also allow you to maneuver underneath objects like this so let me hit play and show you what we're going to make today so if i were to hold down control or c as that is my crouch button for me you can see we're going to have an animation we're going down and up and this is how we're going to be crouching and we have idle and moving like this you can see again we can go underneath this object which we can't when standing but we can when crouching this is very easy to customize as well so you can change the animations change the speed the height all this good stuff which you want but this is what we're going to be making in today's video 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 obviously want to import our animations which we're going to use now these are just four which i've got over mixmo.com and retargeted to the ue4 mannequin and i've also just edited them a little bit just so they're not leaning as far forward or they're not hovering above the ground and i'll leave a download link to these specific animations which i've altered in the description down below so once you've imported those what we want to do is create an animation blend space for them and as so we can nice and easily and smoothly go between idle and moving so we're going to right click go to animation and create a blend space 1d and we're going to do this to the skeleton which we are using for our character which for me is the ue4 mannequin skeleton we're going to set this up for whichever one you are using i'm just going to name this one crouch bs for blend space opening that up straight away in here all we're going to do is change the horizontal axis name to speed and the minimum value is zero maximum is 300 now the reason it's 300 because the default maximum speed the player can travel at when crouching is a speed of 300. if you want to change that you can do and i'll show you in a minute how to but just set that up to whatever you want but again by default it's going to be 300 and that is what i'm keeping as then we just want to import our animations into here so i'm going to the asset browser and what i'm going to do is simply get crouching idle put the order on the left of zero speed and then crouch walking i'm going to put on the third bar in so not all the way to the right but far enough over with a speed of 225 for me so you see if you hold down left shift and move your mouse and move this green dot which is just the preview so when we're not moving we're going to be idle when we are moving we're going to be walking like so and that's just the nice simple way of setting up our blend space but what you also want to do is scroll down on the left to target weight interpolation time and i'm going to change this to be 10 and that just makes the transition between the idle and moving to be a nice and smooth and doesn't snap between them so it just looks a lot better you can change that value to be whatever you want but 10 seems to work well for me so i'm going to save and close that as that is all we need to do in there and next up we're going to open up our player blueprint so for me that's content third person bp blueprints third person character and in here we're going to actually set up the buttons for crouching so what we're going to do first is go to edit and project settings go to input and we're going to create a new action mapping naming this crouch then we're going to set the keys on this to be the c key and also the control key so left control there because people use both of those or one or the other but both those are very common for crouching games so i'm just going to put both of them on there so the player can use either one if they want to i'm going to close that then we're going to right click on our event graph and search the action mapping we just made so i named it crouch like so so you see action events crouch i'm going to get that like that so whenever we press c or left control this action mapping is going to fire off and what i also want to do is i want to make sure that you have to hold down the button to crouch so it's not toggle it's a hold if you want to do toggle come out of pressed and get a flip-flop like so with a is going to get just a crouch function which is already made by on religion and b is going to be the uncrouch which is also already made and that there is toggling so when you press control for the first time it's going to crouch and when you press it again for the second time it's going to uncrouch however if you just want it to be hold then pressed we're going to crouch and released we're going to uncrouch like so and that's a simple way of now crouching and uncrouching i will go over what these functions do since they are already made when we crouch what it does is it just simply reduces the size of the capsule component and then that also lowers the camera down to be a better height and it also reduces the player's speed and all of that together will also set a boolean to be true of is crouching in the character movement one final thing we need to do in here is select the character movement and search for crouch so you see this is all the different options which we can customize so you can change the half height of the capture component change the speed change it to can walk off ledges so maybe like in minecraft when you're crouching you can't fall off a ledge you can't do that here as well if you wanted to just tick that so i'm going to do that as well just to show you and then what we also want to do is make sure we tick can crouch if you don't do that these functions aren't going to work so we need to make sure we do tick can crouch like so close that compile save and that is all we need to do in the character blueprint very very simple because again half of it is already set up for us we're just telling the engine when we do want to crouch and when we do want to stop crouching so let's close that and now finish setting up the animations so we need to open up our animation blueprint which me is going to be content mannequin animations third person and bp but again just do this wherever it is for you and we want to go straight to the event graph like i have here and you should have something similar to this if you don't have one set up already i do have a video on going over how to set one up but i imagine you probably do have it already so what we're going to do is we want to get the character movement from our player so if you're using this message you've got try get pawn owner get movement component and out of that what we're going to do so out of character movement is get is crouching or just is crouching sorry and that again is the boolean value i was talking about earlier which is going to be set to true when we're crouching and false when we're not crouching in the same way we have falling there it just does it automatically for us based upon the character movement we're going to right click on the retelling of that and promote it to a variable naming this is crouching question mark just so we now have a reference inside of the animation blueprint whether or not the player is or isn't crouching so again that way we can change the animations based upon that value making sure to connect all the executions in like i just did there as well compile save and now we're going to go over to the anim graph which we have already set up here as well into the state machine and again you should have something set up similar to this again if you don't already i do have different videos going over how to set up an animation blueprint so i only want to be able to crouch while we're either idle or moving not while we're jumping so i'm just going to come off of this state here i'm going to drag an arrow out of that state and add a new state naming this stand to crouch or stc or whatever you want to call it then i'm going to double click this to open it up with the animation in here being standing to crouched nice and simple like so go back to default drag out of this state and add another state naming this crouch or crouch or whatever you want to call it double click to open that up with this one being the crouch blend space we created earlier and the speed value is obviously going to be the horizontal axis which we set up and that can be the speed value which we already have in here again if you've already set this up you should have that and i do do it in that video as well go back to default drag another line out of crouch to again get another state with this one being crouch to stand and these two here are just the transitional animations from going standing to crouch and crouch to standing as you can tell by the name just so it looks a little nicer and a bit more fluid and then we're going to connect that state all the way back into the idle run state there so i hope that makes sense for you so again we can go from idle to run to standard crouch which will then go into crouching and from crouching we can go to crouch to stand which will then go back into our idle run so now we need to set up the transitional lines going from these so we know when to enter these states so we're going to double click the line going from idle run to stand to crouch first this is simply just going to be get is crouching connected into there so if is crouching is true then we can enter the state so if we can to the state it will go in and play the animation then from that state to crouch what we want to do is go into the crouch state once we finish playing the animation for standing to crouched so we're going to right click and get time remaining ratio standing to crouched like that out of the return value we're going to get a float is greater than a float putting in the value of this being 0.2 connecting that up there now this value may be different for you depending on which animations you are using but it will be a small value like that again if you're using my animations it should be the same if not just keep changing the value and testing out to see when it looks perfect for you so it is cutting off at the right time again basically when there's 0.2 seconds left of this animation so when we finish it it's then going to exit this state and enter the crowd state which is obviously going to be our blend space then from the crouch states to the crouch to stand state that is simply going to be if we're not crouching anymore so when we stop so we're going to get is crouching then get a not boolean connecting that into the return value result there so when we stop crouching this is obviously going to go to false which means we can then enter this transition going into crouch to stand animation in the same way we did stand to crouch to crouch we just want to play it so when this animation finishes so i'm going to double click this line right click time remaining in the exact same way i may not have put the animation in there so let's double click we didn't so that's what we need to do so double click crouch to stand and make sure we do put the animation in there for crouched to standing like so then go back in here right click time remaining ratio crouch to standing with again it being 0.2 for me of a float is greater than a float so sorry if i'm going through this bit slightly quickly it's just very repetitive once you've done the first one you really know what it is you're doing on all of them so again my apologies if i'm going slightly quickly it's just quite a repetitive process in which you should understand what you're doing now but that is all we need to do this should be it perfectly set up for us so again quite a lot of repetitive words here when we're going from idle to run to stand to crouch is if we are crouching then it's going to play an animation once that animation has finished it's going to go into our crouch blend space which obviously includes our idle and walk-in crouch animations then when we let go of crouch so we finish crouching we're then going to go to crouch to stand which will play that animation and once that has finished we can go back to our normal idle run blend space which is again our normal idle and running animations so we're going to compile save and close this now if we hit play this should be it working perfectly so if i were to hold ctrl you can see we have the animation for going up and down like so and if we move about we have these animations working perfectly like so as well so to jump hold crouch you can see that we don't crouch until we then land back on the floor and the capsule component for the collision has also updated so we can travel underneath objects like this which again we can't when we're walking but can when we're crouching so i think that'll be it for this video as we've done everything we wanted to do again i just went over and explained it there but we've updated it so we can now move underneath objects that are lower like this and have the animations working perfectly like so 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]
Info
Channel: Matt Aspland
Views: 27,287
Rating: undefined out of 5
Keywords: ue4, unreal engine 4, unreal engine, tutorial, ue4 tutorial, unreal engine 4 tutorial, how to, ue5, unreal engine 5, crouch, crouching, left, ctrl, control, toggle, hold, anim, animations, speed, height, camera, under, underneath, objects, below, implement, add, low, lower, bp, blueprint, state, machine, ue4 crouch, ue4 crouching, system, easy, quick, easily, on, button, press, input, action, animation, anims, transition, transitions, lines, line, anim bp, mixamo, collision, capsule, component, update, updated, replicated, replicate
Id: XgFvurI_Db8
Channel Id: undefined
Length: 12min 7sec (727 seconds)
Published: Thu Sep 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.