8 Way Directional Movement | Walking Backwards, Strafing And Much More - Unreal Engine 4 Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome back to the range and forward story in today's video we're going to be going over a basic directional movement and what i mean by this is where we can go forwards backwards left and right and also forwards left forwards right backwards left and backwards right so we have eight directions we can move in so if i hit play i'll show you what it's going to look like we can get in walk forwards backwards left right forward right forward left backwards left and backwards right and this also works with sprinting as well and so this is what we're going to be making today and a simple way of making this look better is to just get different animations so i'm going to be showing you the basics of setting all up and i'm going to be using mix more animations so obviously if you have your own animations you could make this look a lot better and also in this we're going to be moving the camera like this so obviously you'd want to fix that and a way we could do that is by using turn in place animations now i'm not going to do that in this episode however if you like i can do another tutorial in the future on doing turn in place so let me delete this code and i'll show you how i've done this so the first step you're going to want to take is you're going to want to import your animations so like i said i'm using mixmo animations so what i did was i downloaded them onto the export here and i just them over so i think what i'll do is i'll probably leave a link in the description down below to my retargeted animations which like i say are all from miximo however i'll leave a link to the retargeted ones for the ufo mannequin and also a link to mixmo as well however again you can use your animations if you'd like so what we're going to do after that is you want to create our blend space because how we're going to determine which direction we're going in is using our blend space and that's to determine our direction and so therefore which animation to play so to do that we're going to right click go to animation and we're going to get a blend space not a blend space 1d but a blend space and then we're going to put this onto our mannequin skeleton or just your skeleton of the character you are using and i'm going to name this directional movement bs for blend space but you can have whatever you want so movement blend space or anything and then open it up straight away in here you can see we have two axes the horizontal and the vertical the horizontal so this one here we want to be direction so i'm going to name it to be direction but the minimum value is minus 180 and the maximum as 180 or 180. the number of grid divisions we want to be eight as we have eight directions and we're not going to be using every single grid however we do want to have eight the interpolation time will leave to zero the vertical axes we want to be speed so then we can also run in this as well if we wanted the minimum is zero the maximum as 600 or whatever the maximum speed for your character is so for me that's 600 and sprinting i have a 600 and walking is 300 so when a sprint is 600 but if you have the maximum as 1200 let's say you'd put 1200 in there so just this is the maximum speed of your player number of grid divisions put as three and now in the bottom here we have this grid where we're going to place our animations now in hindsight this is fairly simple it's not too bad we just got to put the animations in the correct places so the part which took me the longest figuring this out and coming up the code was figuring out which places to put the animations in however i'm just going to show you where to do it so i made the code earlier and as a reference image i've made one which i will link in the description down below and it's this image here i'll probably put it on screen as well as justice photoshop document but basically i've just taken a screenshot of what i had earlier and i've just written underneath where i have everything so if you want you can pause the video now and have this on screen and put them all in however i'm going to go through it now as well so if we go back in let's put those on so we'll start with the basics so what's that that's idle so we're going to get our idle animation for me that's third person idol i'm going to put that on the bottom row here so this is when we aren't moving i'm going to put it on every other square like so so we have five down at the bottom like so and then we're going to go for walking and this is going to be walking forwards so for me i just want my normal third person walk i'm going to put that just above the middle idle there so we're still in the central column going up like so and then skipping this one here and going right up to the top we're going to have our running so for me that is the third person run there it is and the reason we're doing that is because this is direction obviously and this is speed so the higher up we go the faster we're going and anything to the right of the middle is right anything to the left is left which means we're moving left so we're walking left sorry so now let's just set up all the walking animations so we've got our idle walk and run now let's set up the walking so let's do walking backwards first so let's find our animation for walking backwards which again you have here in the bottom right sorry i don't know if i mentioned that all your animations are in the bottom right in this asset browser here so walking backwards for me is here so it's going to be all the way on the left on the first one up and all the way on the right on the first one up as well so that's going to walk backwards and if we hold down left shift and move our mouse we can preview the animations so we have idle walk and run and then walk backwards as well this is the animation which i've got and now we want to walk right so we're strafing right so to do that what i'm going to do is get my right strafe walking and put it in between my walk and walk backwards so it's in the middle there now we have right straight walking like so now it might look like it's left to you but if you move the camera so you're basically possessing the player it's gonna be walking right so it's just mirrored because of how we're looking at it and now let's do the left stroke walking so again we'll get left stroke walking in between walk and walk backwards there on the left hand side this time so this bottom row we need to fill up completely so in between our walk right and walk backwards we want to have walk backwards right which makes sense right we're walking right so if we're not walking fully right and we're not walking fully backwards we're walking backwards and right so diagonally so what i named this one was run it backwards right now my walk backwards and run backwards are the same animation however obviously you can get your own different animations for each one as well or you can just duplicate it and speed it up but i'm going to be using the same one so run backwards right for me i'll have it as there and then in between the walk forwards and walk right i'd have walk forwards right so for me i called it run forward right let me see if i can search for it forward right run there we go so forward right run there sounds just gonna be walking walking backwards walking right walking forward and right backwards so now let's do the same for left so this is the exact same we're just reversing it for left instead of right so in this slot here we want to have walking forwards left as it's between forwards and left so forward left run will be there and in between backwards and left we'll have walking backwards left so you can see it's quite simple to wrap your head around run backwards left there so that is now the walking completely set up so now let's do the running so let's do running backwards first which again is going to be on the far left and far right so that's running backwards there which for me is this animation set up perfectly in the corners like that and then again we have run there one over to the left of run went to forward left run actually let's do the strafing first again so again we have our left strafe there we go all the way up to the top we're going to have our left stroke running so for me i named it left straight for running so let's put that in there directly above the right stroke for walking we want to have right stroke running so put that in there like so and again how we did the walking in between them we want to have the diagonal ones so in between run and run right you want to have run forward right so you see if we don't have one it's just going to kind of bunny hop over like that so for me that is run forwards right or sorry i named it forward right run there and then forward left run over there so again very simple to do and i believe that should be it done let me just double check for my reference image yep that is all perfectly set up now so we have idle walking forwards and running and we also have our strafes so walking and running left and right and also diagonally as well between them so we have our directional movement for eight different directions like so now if we save we can minimize this as we're technically done with it however it's always good to just keep it open in case we need to come back so we'll minimize that and the next thing we want to do is we want to put this into our animation blueprint so for me i'm gonna go to content mannequin animations third person and in bp and in here i'm going to go into the state machine so let me just delete that sorry that's from earlier i thought i'd delete this code but the engine did crash so it's not fully gone so let me just do that so sorry about that like i said we want to be in the state machine so you might be in this anim graph here double click the state machine and we're going to our idle run state here if you don't already have one i do have a video setting up an animation blueprint as well so i recommend giving that a watch and then you just essentially change this blend space here for the one we're about to create and in that i do also go over setting up the speed and direction variables as well so if you don't have animation blueprint i'd recommend watching that although don't worry we will also set up the direction available in this video if you don't have that so what we're going to do is just delete this blend space which is already here and replace it with our directional movement blend space there so that's just an animation directional movement blend space there like so and we can plug the speed in as we already have that now we need to make the direction so we can go to the event graph and then we should have some space here we'll right click and we'll get a calculate direction to return value of this we're going to right click promote variable and name direction plugging that into one of these executions here so that we're setting it and if you don't have another execution you can just plug it straight into here like so off of your cast target will be self velocity will be get velocity for a character which i have up here but again you can come off of your cast and just get velocity like that now for base rotation we want to come off of our cast again or reference to your character and get actor rotation plug that into the base rotation like so and now we're setting up and calculating the direction so we can compile and save that go back to our state here and for direction we're going to plug in our direction variable that we just made so this is how we're going to be determining which animation to play based on our horizontal and vertical axes of direction and speed so you can see all of our different states in here like so so that is the animation blueprint setup so we can compile and save that and there's one other thing we need to do and that's in the character blueprint so i'm going to open that up for me which is content third person bp blueprints third person character then here you can see i just have a basic sprinting mechanic i do have a video on that as well if you'd like however all it is is simply just when i hold down left shift i'm going to increase the speed i'm going to let go go back to default what we're going to do is we're going to select the character movement up in the top left and the top right i'm going to search rot for rotation and we're going to untick orient rotation to movement and tick use control the desired movement so we're going to essentially rotate the player wherever the camera is moving and when we press a and d or s that won't rotate the player so that's going to allow us to actually use our strafing and walking backwards animations which we just set up so now if we compile and save this should be up working so if we minimize and hit play to test this out we can see if this is working so if we move the camera we're going to move like that which again we can use turn and place animations to make that look better if i go forwards i'm going to play forward animation i'll go backwards we're going to have a backwards animation left left stroke right right stroke and let's check diagonal as well we can go forward diagonal both directions and backwards as well and this also works with the sprinting perfectly as well like so so this works perfectly so we've set up our basic directional movement in today's video where we can move forwards backwards left right and also diagonally in these directions as well and again in a future episode we can set up time and place to make that one look a little bit better but this works great so far so thanks so much for watching i hope you enjoyed 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
Info
Channel: Matt Aspland
Views: 134,374
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, ue5, unreal engine 5, directional, direction, movement, movements, moving, locomotion, directional movement, directional locomotion, 8 way, 4 way, walk backwards, ue4 walk backwards, turn in place, forwards, backwards, left, right, strafe, strafing, diagonal, 8 ways, ue4 8 way movement, ue4 8 way locomotion, advanced, animation, animations, anim, blueprint, blueprints, speed, blendspace
Id: OSWX3vEgRcE
Channel Id: undefined
Length: 12min 9sec (729 seconds)
Published: Sun Feb 21 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.