8 Way Locomotion System - Strafing - Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys and welcome back to another Unreal Engine 5 tutorial I recently made a video on a blend spaces and what they are and what they do and today I wanted to use blend spaces in order to create an eight-way locomation system or a strafing system um so just to give you an example of the things we'll Implement that will allow a character to move forward of course um but then if we wanted to go diagonals um and then sides as well right and left as well as backwards um we would have animations plugged into a blend spaces to allow that so our character would follow the the direction of the camera but then we we would also be able to move in any direction we want while still facing the camera now for this tutorial I'm going to be using some of the animations are available in the movement and S pro if I remember correctly I think I was lucky enough to get that for free at some point now unfortun fortunately uh the anim set comes with a price but you know you get to support uh content providers but you know it will work with uh your animations uh you could also go to Meo and find the animations you need I know for a fact that you'll you'll find all the animations that are required for such a for such a system over there and then import them to your project and retarget it into the unreal mannequin I also made a video on how to do just that so make sure you check that out if you're not very familiar with the uh with the process okay so from here I'm assuming your animations are ready to go so the next thing we want to do is to create our blend space so I'm going to do just this uh in my own folder um so let's right click and do animations blend space I'm going to use my skeleton make sure you use the uh yours or the the unreal mannequin one by default if you want to and I'm going to call this one uh blend space strafe okay let's open that up um so when you create a blend Space by default it's the two dimensional blend space in noral um if you wanted to do a 1D blend space it's under Legacy but uh don't worry this is the default one this is the one we want so on the over here on the left side here this is where we're going to be able to Define both of our AIS so we'll start with the horizontal one which is going to be our Direction and then uh the direction will range from minus 180 to 180 and since we have eight directions will'll divide the grid uh in uh in eight divisions yes I'm going to check snap to grid that's going to be easier for you to uh drop the animations exactly on the the space Sorry the point in space that you want and then for the vertical axis we'll go with the speed that ranges from 0 to 500 which is a default top speed or maximum speed of a character un real uh and then I'll check snap to GD as well okay now we're going to be ready to start adding our animations so when the speed is zero we're going to start by plugging uh our idle in that so you you'll have to do it in um on all the direction divisions so eight times okay and now now I'm going to have to be careful because what animation um I plug on which uh division matters so I'm going to just I have type run just to filter the animations I really need because they all contain that keyword and so let's start with a direction of zero which is forward so I'll go ahead and move the uh um sorry to and place the forward Loop this direction is going to be right and this direction is going to be left so if if uh we're going that way that means our stick uh we're actually rotating clockwise so we'll go with um right 45 I'll plug the right loop after that and then right 135 which is backward right and then the backward Loop now backward Loop also goes into minus 180 um if you've watched a video about blend spaces you know by now that uh minus 180 and 180 are the same angles and we'll do the same so we'll go um forward left which is left 45 left Loop and then left 3 135 which is backward left okay now let's save this and now what we can try is double check that we did good uh so we can press play which will make um all the animations play in Loop and by holding control and moving the mouse over we can we can move the parameters and so we're going to be able to check our animation so this is forward forward right right backwards right and then backwards and let's go this way we backwards diagonal backward left left forward left and back to forward okay it looks like everything is working we did a great job now the next Tas is going to be to calculate both the direction and the speed using the even graph so that we can plug those two variables in our blend space so that it can work in game and react to our input so I'm going to close this and go to my animation blueprint okay so we're in our even graph uh this is uh with a few exceptions the default even graph on of Unreal Engine 5 um but I will go ahead and we have a ground speed here that we could technically use but just for the sake of the the tutorial we're going to be recreating both the direction and the speed together so the first thing we want to do is to right click on an empty space here and look for try get Pawn honor which will uh try to get the owner of that animation blueprint which is going to be our character and I'm going to drag off from the return value here uh and I'm going to type is valid and I want to take the one with the question mark now this is just a check that will ensure that we do indeed have a character um and then if it is valid then we'll do it if not then we won't do anything which avoids any potential problem in your project now I want to drag off a second pin from the return value as well and I want to look for a function that says get velocity okay and then uh from the return return value here get velocity I'm going to look for a function called Vector length length and the return value here I'll drag and I'll select promote to variable that uh that will be called speed okay and now from is valid I can get the flow of information and then I'll just add a a a fourth pin to my sequence here so that you know the difference is that they're they're all going to be executed in order one after the other and so I just just for organizing things I added a a new um output and um once this is done we'll go into hours and if this is valid we'll set the speed and now the speed is correct and calculated and we now need our Direction and so a third time we want to drag something from our character here and we look for a function that's called get actor rotation now from the returnal value here I'll look for a function that's uh called calculate Direction and as you can see it also requires the velocity to properly calculate so we'll just drag it from that function over here and the return value from calculate direction is sorry our Direction which means my mistake we want to promote it to a variable as well and we'll call it Direction and then we'll connect the set direction to make sure it's being it's getting processed compile and save and we're good to go so now that we have both our speed and our direction we're going to be able to create our blend space in our anim graph and plug those in in order to make it work in game so let's move to our animation graph here um it doesn't really matter what you have just uh just be sure to plug it properly where it makes sense for your blend space to be which is pretty much going to be in your you know Locomotion state or if you have a run state a work run uh in the uh default third person unreal project is going to be here in Locomotion then you'll see that state machine and you want to go into walk run um I have some things on my own but I unplugged everything just so that we start fresh together so uh we'll first start to drag our blend space from the content browser um so mine is saved under animations and I'll I'll drag our um my blend space here we'll plug it to the animation output pose and as you can see it requires two variables so we can simply go to our variables here and then um drag the direction and then if you release it on the input here it will automatically get the connection for you and then same thing for the speed let's compile and save all right let's try in game I'm going to go and press play and now as you can see the problem I'm having is that I can I cannot see my animations just because my character keeps facing the direction of the motion so we want to change that so let's uh stop the game and we need to go to our animation third person blueprint which is by default uh under third person here as you can see we have BP third person character here we want to double click on that to open it up and then uh you want to click on on select curve movement and on the details on the right just to make things easier just start to type rotation and uh so you want to uncheck Orient rotation to movement that's exactly what we just saw in game we don't want that we want the character to keep facing uh what the camera is dictated so we want to uncheck that and to make sure the camera faces sorry make sure the character faces the camera we want to check uh use controller desire rotation all right let's compile and save and try again now as you can see the camera drives the orientation of the character and if I start uh moving around my character will play the animations we just created in Blade spaces accordingly now one thing that we could fine tune because it bothers me a little bit is that you know I'm using a keyboard um but it's not really smooth you know the selection of the animations happens too fast that's something you can easily change by going back to your blend space so let's let's um stop the game we'll go back to our blend space animations blend space strafe and sorry let's pause the preview and uh down on the uh the left here right after your uh AIS settings you have a an option here is that's called weight speed um I'm going to set this one to three and and then compile we can close it start the game again and as you can see now even with a keyboard um the animations are much smoother that's because that parameter just changes how fast the sampling happens which technically means that um you're you have a small lag in getting the direction you want now be careful with this um because if you're getting if you get a if you set a parameter that's too high it will impact responsiveness right so it could get frustrating for players uh three is a is a pretty decent amount I still my character still goes in the direction that I want fairly quickly so that's enough all right guys once again I want to thank you for being here and watching this video I sincerely hope it was useful as you can see blend spaces are not rock in science they just require a tiny bit of knowledge but once you get the grasp of them you're going to be able to make a brilliant things I want you to have fun working on this and playing around I want you to take care of yourselves and I'll see you in the next one
Info
Channel: Matt Courtois - Technically Animation
Views: 10,765
Rating: undefined out of 5
Keywords:
Id: ah5ORNR8ZUk
Channel Id: undefined
Length: 13min 8sec (788 seconds)
Published: Tue Feb 13 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.