Unreal Engine 5 Easy Rootmotion System Tutorial | Walking & Running With 8 Directional Movement

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what is going on guys this is your boy astrum sensei and today i'm gonna be showing you how to create a basic root motion system in unreal engine 5. so in this tutorial we are going to be creating the simplest unreal engine root motion system which will have eight directional movement and will have you switch between walking and running so i'm gonna call this project name basic root motion system or without system just basic root motion and i'm gonna press create so here we are in our third person project and i'm not gonna be starting from scratch because it will take more time basically we are gonna be using the third person character as a base so i'm gonna double the content browser in the layout and then i'm gonna go to the third person bp folder to the blueprints folder and we are gonna take a look at our character blueprint so this is the character blueprint and we have our event graph over here now what root motion is is it's basically a system that moves the player based on what the animation is doing so if the animation is walking then the character will move based on the feat of the animation so we do not want this one because what this does is it adds movement input to whatever input you are pressing and what that does is it moves the character even if the animation is not moving so we do not want that at all i'm just gonna press alt and disconnect them and move the move forward and move right separately we wanna influence the movement based on the animation so to do that we are gonna make edits in the animation blueprint i'm gonna go to the mannequin folder and we are going to go to the animations folder and import my own root motion animations now i downloaded these from mixamo and converted them using a mixamo converter but what you can do is you can just grab any animations from the marketplace and it will work perfectly i'm gonna ch choose four which are walk back walk forward walk left and walk right and i'm gonna choose run left run right run forward run forward diagonal run backward diagonal and run backward i'm gonna use the run forward and backward diagonal for the walking as well but i'm gonna slow them down i do not have diagonal walking animations so sadly i cannot add them but i can try to compensate for that with the run diagonal animations no problem but anyway we're just going to place them in our folder and i'm going to choose the unreal skeleton now because i use the mixamo converter i'm gonna need to change a few settings you do not have to do that if you didn't use it but i'm just gonna change them based on the mixamo converter so here we have it now i'm gonna do this and yeah i think we should be good to go so i'm just gonna click on import all and that should import all of our animations now what i'm gonna do is i'm gonna right click and go to asset actions and bulk edit via property matrix and what that does is it edits all of them at the same time what i want to do is i just want to enable root motion so i'm just going to go over here and press on enable motion and the root motion pose will be the reference pose just close this and we are going to go to the nmvp now we are in the default animation blueprint you can actually start an animation blueprint from scratch but to save time i'm actually gonna do it using the default one which is included in the engine so the root motion we are gonna enable it root motion from everything this this tab the details panel will only be there once you open the animation blueprint so if the animation blueprint was already open and you have something in the details panel it will be kind of hard to make it show up unless you close the animation blueprint and reopen it so anyway here is our character event blueprint update animation drag it pawn owner then we check if it is valid then we set the is in air this is for the jumping and this is the setting speed so this one sets the animation based on the speed it sets the speed variable which sets the animation blend space to choose from walking and running so we're going to delete this entire part because we do not need it what we need is to we are also going to delete the speed variable because we do not need it as well right now if you actually try to play it will no longer be working because you cannot move around in that animation and there is no speed and we activated root motion but don't you worry about that we are going to be fixing that right now so over here in the anim graph what we have is a state machine and inside of the state machine we have a few states for animations now this is the main one we are going to be working on the jumping we are not going to be changing anything because it doesn't require root motion but for this one you can just open it idle and run this is the blend space that blends between the idle and running animation what we want to do is we want to delete this because it will no longer be useful for us we're going to create our own blue blend space and it will be a root motion blend space so we're gonna go to animation and choose blend space choose the unreal skeleton or any skeleton that you are using and i'm just gonna call it movement blend space and i'm gonna open it now this movement blend space we have all of the assets over here that we have and this is where we can set the speed for sides and forward so for this one we are not going to be calling speed because this is no longer the character walk speed this is actually the amount of input that the player is putting so we're going to call it site input and the other one is going to be called forward input and we have a minimum value and a maximum value so this is the minimum input and this is the maximum input the minimum speed is going to be minus two and the maximum speed is going to be two so basically one is for walking and two is for running and we are going to do the same thing for the forward so you can move forward either backwards or you can either run backwards or run forward and now we are gonna go and grab in our idol animation oh i forgot to add in an idol animation so i'm just gonna drag in one over here we have in place yeah i placed it in the in place folder because idle doesn't need root motion but yeah i'm just gonna import it and it should be perfect now we can just go in here and item the idle animation the idle will be at side input and forward input zero the run forward will be at side input zero and forward input two the walking animation will be at forward input one so here it is we walk forward we run forward or we idle and i forgot to change the interpolation time which changes how fast it swaps between animations we want to make it a little bit slower so i'm going to make it 0.4 and now it's no longer snapping and it's more of a smooth transition now we are going to place in the work backwards at -1 and they run backward at -1 as well and now you can see that you can move forward and backward and of course you cannot do it it's just the character that is moving i'm also gonna place run left and run right so let's actually not do the rest of them right now go back to the nmvp and since we deleted the previous blend space we are just going to grab in the movement blend space and we are just going to connect it to the output pose and that should make it work however we do need side input and forward input so we are going to need to add that right now but where do we get these from well we get them from the character itself so we're gonna go back to the character blueprint and we need to bring them from the axis value so the move forward is we're gonna promote this to a variable i'm going to call it input y which is forward and we're going to set the other one which is going to be called input x which is side and of course i forgot a bracket but let's do it like this yeah here we go now we are going to compile and we are gonna go back to our blend space or into our animation blueprint and we need to get that those two variables from over there to over here so we're gonna do that using the event graph what you can do is you can drag at pawn owner then you cast to the character and then you get the variables however i do not think it's a good idea to use it in the update animation you can just get a reference to the character at the begin play and then you get the variables from it because i think that would make things more organized so i'm just going to type in event we can play or event blueprint again play and we are gonna cast to third person character the object will be try get pawn owner so i'm just gonna duplicate it from here to over here and connect it to the object and we are gonna just promote this to our variable which will be called as third person character now if we go over here after we set is in air we are just going to get as third person character and we need to get these two variables which are influenced by the movement or how much you are moving so i'm gonna go back over here and we are gonna get y input and do the other one which is get x input and what you want to do is now just right click on it and promote it to a variable which will set it as this variable which so that we can connect it to the blend space this is a very simple motion system and it's the simplest i can come up with [Music] but despite the fact that it's simple it's actually very compatible and it works perfectly with everything so i really recommend trying it out anyway now that we have set the input for y and x we are gonna compile and go back to the third person uh sorry we're gonna go back to the anim graph and we are going to change the idle run over here we're just going to connect the side input to the input x and we are going to connect this one as well and now we are going to compile and i think we should give it a try and see if it works you can see that it actually works for the forward and backwards walking the right and left it doesn't work perfectly i think i forgot to add animations for it so there's that but if we go back over here there is an issue and that is because we are guesting from this one i don't know why usually it works but in unreal engine it isn't working it's causing an error i mean it does work but it doesn't an error so i'm just not gonna use the reference thing and i'm just gonna grab it and delete this one as well just connect it like this and the the error should no longer be there i don't know why this error is happening despite the fact that the game actually works perfectly so yeah i just found out that this is a more appropriate solution despite the fact that that one is more organized anyway we are going to go back to our blend space and we are going to look at what we added we have the run right actually we need to revert these sides there is something wrong with this or maybe it's me who's doing it wrong yeah i think it's me because you want to look things you want to look at things from this perspective i guess yeah definitely so run left over here round right over here we are going to add in the walking as well walk left over here actually no walk left is over here walk right is over here [Music] and let's add the diagonal very quickly as well so run backward diagonal it blends perfectly with the running and we add the other one over here run forward diagonal which blends with this one and the other one is over here and sadly we do not have walking diagonal animations but we can just place the ones we do have and add slow them down if we want so i'm not gonna give it a try but you can just place it where the walking is actually let's let's give it a try there's no less than that i'm just gonna go over here and change the rate scale to 0.5 so that it's half the speed and do the other one as well so rate scale 0.5 i don't think there's a point in it because it does change the rate scale anyway when you are walking but there is no animation but there is no loss in trying it so i'm just gonna give it a try so right now if we play you can see that it actually works perfectly but we still cannot run and the character no longer rotates so we're gonna have to figure that out so first of all we are gonna look at the running thing i'm gonna go to the project settings and i'm gonna add an input for running so action mappings press plus type in run and change this one to left shift and close it now if we go back to the character in the event graph i'm just gonna type in run i'm not gonna make this really organized because i do not need it as a project i do have my own project which is very organized but for now i'm just going to make it like this which is very random what we want to do is we want to create a new variable which is called running and we are just going to set running to be true and when we release set running is going to be false so when we are no longer holding the left shift running is going to be false and then we are gonna create a branch over here we're gonna get running and create a branch we're gonna check if we are running when we move the forward input stick and if it's false we're gonna set it normally but if it's true what we wanna do is we wanna multiply it so that it's more it's double the speed so that it's two no longer one so i'm just gonna press on multiply and over here change the number to two and we should copy this for the other one but let's just make it a little bit more organized i can't handle this anymore yeah that's a little better so we need to copy this entire thing for the other one so i'm just going to copy and paste and i'm going to leave the previous set connected to this one the input axis is going to be this and we are going to need to replace these variables with the input x so just drag it and change node to write input x the other one over here and click compile and i think that should be fine right now let us give it a try if we press play we start walking if we press shift we start running and we can run in all of the directions and the way you can speed up the character when you are running i mean the only way with the root motion to do that to do that with root motion is to change the animation play scale to make it faster or you can create faster animations if you are an animator and you are creating your own root motion animations this actually looks better with the female mannequin so i'm just gonna go there to the details panel and replace the mannequin very quickly and press play and you can see that the female mannequin has better i mean she looks better with these animations because because these animations are more suited to someone who is more agile so this female mannequin she's just the perfect fit anyway now we are moving in all of the eight directions however we cannot rotate why is that and you know the rotation is not gonna work at all even if you use orient rotation to movement so we are gonna find a way to fix that so to fix the rotation we are going to go back to the third person character and what we need to do is we need to set the actor rotation based on the velocity and the vector length so we are going to do that using the event tick so just grab an empty spot and type in event tick and i know i'm not being as organized as usual since this is a one-time tutorial i decided that i'm going to be not organized because you know everything you can just cut it and paste it whatever you want you can create your own graphs it doesn't matter as long as the code works everything will be fine so yeah we are just gonna go to the event tick and we are gonna set actor rotation and then we are going to decide what we want to set it as so the new actor rotation we are just going to get actor rotation and we are going to get the control rotation and we are also going to get the velocity and we're gonna get the vector length of the velocity after that we're gonna place it over here and we're going to check if it's smaller than or if it's greater than so if the vector length is greater than 10 then we are going to branch and we are gonna set and if it's true we're gonna set the actor rotation and of course you wanna connect the event tick to the actual branch like this and the new rotation we're gonna split that so split struck pin we're gonna get the actor rotation and we are gonna our interp two the current is the actor rotation and the target is the control rotation we're gonna connect the new value oh sorry i forgot to split this so we're gonna split the return value and connect the z to the z and the delta time is gonna be the event tick we're going to move it like this and i think it should work now so if like if i compile and give it a try you can see that the character actually turns now however they do snap so the way to fix that is to actually change the interp speed you can change it to whatever value you want i'm gonna try 10 and if i play you can see that we can turn now which is great i think 10 is way too slow so we're gonna go with half of that i'm gonna go with five and if i press play you can see that the rotation works perfectly now and of course it's better to not use the content browser when we are previewing it so as you can see we have the root motion system and it's working in all eight directions with running enabled and if you want to do sprinting you can just multiply the the number with three after running so you the possibilities are endless so if this tutorial is useful for you please make sure to subscribe and like the video for more awesome tutorials and if you'd like to download the project files they will be available on my patreon so go check that out i will be organizing them for the patrons so don't you worry about my mess which i did in this video so yeah that's all for today i'll see you next time take care have a great day and bye [Music]
Info
Channel: AstrumStudio
Views: 70,295
Rating: undefined out of 5
Keywords: unreal root motion, ue4 root motion from everything, unreal locomotion, root motion blendspaces, ue4 root motion blendspace, unreal root motion blendspaces, unreal root motion blendspace, ue4 root motion movement, ue4 root motion walk, ue4 root motion run, unreal root motion movement, unreal root motion walk, unreal root motion run, unreal engine root motion, unreal enable root motion, unreal animation root motion, unreal mixamo root motion, ue4 root motion guide
Id: d3x9z31JE3E
Channel Id: undefined
Length: 21min 58sec (1318 seconds)
Published: Sun Jun 06 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.