UNREAL ENGINE Attack Animations (Easy Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everybody today i'm going to show you guys how to add weapons to your unreal characters and attack animations this is perfect for game devs or for creating cinematics for unreal engine so i'm going to build this on our previous unreal character video so if you haven't watched that or you don't already have an unreal character set up go ahead and go watch this video right here you're also going to need an attack animation so go over to miximo and grab one maybe two or three however many you want i recommend you keep them kind of simple though so no spin attacks no combos just a simple swipe or a punch or something like that and then lastly you need weapons and luckily we just converted some of our pre-existing medieval weapons into unreal engine so if you go over to the unreal marketplace you can see they're actually just right here and you can click buy now and download them and it will install it right to the project if you already are a pro member we've got you covered we uploaded these to the render crate store if you did download these weapons directly from the render crate store here's how you install it once you've created your unreal project go ahead and go to where it's saved and open it up and you should see a content folder in there just drag and drop the weapons right into the content folder like this and now the next time you open it the weapons will just be there so if you followed along with our previous character video we're picking up right where that left off let me show you now if not the superhero character i actually used our skeleton character because i just wanted some variety but you can see it's all the same he runs around if i hold down shift he'll sprint and if i right click he walks just like the superhero character from before now if you go into your content browser just to double check we should see that the weapons have installed and they're right here we can double click on one and take a look so now we need to attach it to our character you'll notice this time around i actually picked animations where it looks like he's holding something because the previous animations we made in the previous video his arm was just kind of down to the side it didn't really look like he was holding something so i swapped him out for animations where the character's holding something in his hand so i'm going to open it up and i'm going to navigate to my skeletal mesh that's right here it's the one with the pink line under it and it says skeleton mesh so if you open that up this is where you can look at all the bones in your character's rig i'm going to go down and find his right hand bone now it's called that because i'm using the mixomo skeleton if you're using some other skeleton it might have a different name but it's it's his right hand so here it is and i want to right click on that and click on add socket and we can name this socket it's probably a good idea so i'm going to name this weapon socket you can call it whatever you want if you have a two-handed weapon or two different weapons you can call it left-hand socket right-hand socket whatever you want and you can put a socket on any bone so if you want him to have a shield on his back or a hat or anything like that you can put a socket on any bone so i'm going to right click on my socket down here and i'm going to go to add preview asset and i'll just type in sword just to grab one of the swords we just created and we can see that it's not really lined up with how it should be in his hand so this is our opportunity to get it positioned just right something to keep in mind this is just a preview it's not actually connected to him yet it's just showing what it will look like when it is connected so that we can get it positioned just right so i'm just going to move this down into his hand don't worry that he's not gripping it i just want to put it sort of floating in his palm and if you're doing a game and it's got multiple different weapon types you can actually have a different socket for each weapon so that they all fit perfectly in the hand but just to keep it simple we'll just have this one socket right here so i'll go ahead and save the asset and i'll close it and again if i press play i can see he's not holding the sword that was just a preview let's go actually attach it to his body so this time i'm going to go into my content folder go into the third person folder and go into blueprints and here's the bp third person character it's the third person character blueprint that comes with unreal engine now if we click on viewport we can see in the previous video we already swapped it out with our character so that's why we see the skeleton here or your superhero or whatever and i need to attach a static mesh one of those swords to this skeleton so i'm going to go over here to the left and go add static mesh and you can call it whatever you want i'm going to call it weapon and this needs to be parented to the skeleton so i'm going to drag and drop this onto the skeletal mesh right here where it's called mesh character match right here notice now it's nested underneath that but it doesn't really know which part of the skeleton to follow so over here under the details we want to search for sockets see this one that says parent socket if you can't find you can always type in socket like that but it's right here and i'm going to click search and i'll choose my weapon socket again if you don't see it you can search for it so now we have this thing floating that's kind of following his hand right now it's nothing it doesn't have a mesh attached to it so i'm going to go over here to static mesh and choose the arming sword notice it's not really connected we took all that time to line it up and it's not where it should be for some reason unreal engine just adds these strange transform values right here so i'm just going to click these little arrows to reset it to default and it should pop into his hand now what's really cool is if you have multiple weapons like we do you can actually switch this out for a different one so let's do the axe and you can even adjust this so let's say we have the ax but it's not quite sitting the same way as the sword we can actually go here and adjust these values to make it sit right where we want it inside the hand but i'm gonna go back to our arming sword because that's the one i like you can actually scale it too if it's not the right size now we got a little bit bigger sword i'm gonna press compile and save and we'll press play to test it out nice now he's got a sword in his hand now the problem is when we click he doesn't do anything so the next step is going to be to add the animations in okay so i've actually gone to miximo and i've picked out five attack animations that i like one will do but i just like to go above and beyond so here are my five animations and i'm just going to drag these into the content browser to import them and it's always important to not import the mesh and also very important you want to pick the target skeleton so we don't want this to go onto the default mannequin we want it to go onto our skeleton character so i'll click that and press import all alright so here's what one of them looks like at this point you can actually edit these animations if you want to so this actually is kind of slow for a game it would feel very sluggish so i'm actually going to go over here to rate scale and let's try one and a half speed a little bit faster we can try two but that's probably too fast so this is where you can dial in the feel of your game if you want to be really quick and snappy like street fighter you can really speed it up if you want to feel more slow and more realistic like the witcher then keep it how it was captured with the motion capture suit i'm going to go to 1.5 and you can even trim it if you want a really quick and snappy instant response sort of feel you can actually trim off all the frames until right before he's about to swing i think i'm going to trim off just a little bit here so i'm going to scrub to where i want to cut so i'm actually going to right click and go remove frame 0 from 246 so it's just going to cut off a little bit of the lag in the beginning and then at the end of the attack i can see that he kind of goes back to neutral about right there but then there's still a lot more of just kind of moving his body and not doing much so i'm going to cut off a little bit of that too let's watch our finished animation so a little bit quicker it's going to feel a little bit more responsive when our players play our game i'm going to really quickly do that to all the other animations all right i got my animations sped up and trimmed up they're ready to go to make this work we're actually going to have to right click and convert them into animation montages just the attack animations so here this attack animation i'm going to right click and i'm going to go create anim montage and i'm going to name this animation montage one okay and i'll do that for each of the animations okay so i've got five animation montages now one through five let me go ahead and save them and now to get this to work we need to edit our animation blueprint so right here i'm going to click on nmbp skeleton and if you watched that previous video this should look familiar this is where our state machine plugs into our output pose i need to create what's called a default slot to get this to work i'm going to put this in between all this does for us is it allows us to play animation montages on top of the default movement animations that we already created just kind of hijacks it so i'm going to click compile and save so right now nothing's going to happen we have to actually set up the input which is going to be the left mouse click or whatever you want it to be so let's set that up too let's go to the third person blueprints and i'm going to go to bp third person character if you remember this window it's where we attached our sword to our skeleton but if we go to event graph and find an empty space usually kind of near the bottom this is where we can set up inputs so i'm going to right click and i'm going to type in left mouse button so this red thing is called an event and the event is when the player clicks on the left mouse button it's going to play the animation montage so let's go out from the pressed execution pin and i'm going to search for animation montage play and in montage right here and i'm going to say under enem montage select asset i'm going to choose just my first montage the first attack and i'll hit compile and save now when i press play and i click i can see he does the attack which is really cool now we have a problem when he's running you can see it overrides his legs animation too what we need to do is we need to make it so only the top half of his body plays the montage and the bottom half plays the default animation so i'm going to press escape and here's how we set that up i'm going to go back to my animation blueprint nmbp skeleton and what we need to do is we need to blend between this default slot which is the montage playing and the state machine which is the legs moving so i want the montage to play on his top half and the legs to play on the bottom half so here's how we set that up i'm going to create a pose so out from the state machine i'm going to drag and i'm going to search for pose i'm going to click on new save cached pose and it's got a random number attached to it so we can just call this walking animation so once i've created that i'm going to right click and search again for cache and where it says use cache pose walking i've got this thing now and i'm going to plug this into our default slot i'll press compile and save and right now we haven't actually changed anything all we've done here is we've kind of created like a little teleport machine so you can see our walking animation is going into this cached pose and then it's coming out of the cache pose into here so really nothing's different we just kind of created like a little teleport for the information to flow if we were to press play nothing would look different though but now we need to blend these two things together so i'm going to go search for layered blend per bone so what we need to do is you can see here we've got an input for two poses and what we can do is we can plug two different animations into the different slots and then choose a bone and that point will be where it splits so if we choose the center of the chest then from that point up the arms will move and he'll play the attack animation and from that point down the legs will move or we could pick the elbow for some reason if we want just the elbow to play the attack animation so it's totally up to us but let's get that plugged in first thing i want to do is take this these two here and i'll plug this into the bottom slot blend post zero and then i'm gonna search again for that cache pose so i'm gonna search for use cache pose walking and then i'll lastly plug this into our output pose let's press compile and save so that might have been a little bit confusing but let me just explain what's going on remember the cached pose walking is just the default walking animation that we already set up and it's flowing into here and then this part that we set up if you remember is the walking pose but it can be overridden by that attack animation that's what this slot does so we've got one version of the animation that's just him walking and one version where he's doing the attack and this green note here is going to let us blend it together let me show you how that works so i'm going to click on this and i'm going to go over to layer setup open up this index here and where it says branch filters i'm going to click on the plus sign and then open that up so what we've done is we've said we want to pick one spot where the animations branch so what we need to do where it says bone name we need to pick the bone where above it it's going to play the attack animation and below it is going to play the legs now if you're using the miximo skeleton that's called spine with a capital s if you don't know which bone or what it's called you can actually go into your skeleton right here it's the the one with the pink line and just go find the name of the bone kind of right above the hip bone so again right here you can see the hip bone is right here in the pelvis and right above that the next joint up on this skeleton is called spine on your skeleton it might be called something else make sure you name it exactly the same so what we're saying is here above the spine bone it's going to play the attack animation so let's go ahead and see what that looks like i'll press play and i'll click okay he's doing what we expect and if i run his legs keep moving and he's playing the attack animation now we do have another problem here that we need to fix and it's very easy to fix but let me show you if i make it so he's facing right at the camera and i attack you can see he's not really attacking forward and the reason for that is if we look at the animation you can see the animation we picked he's kind of leading with his hips and he's twisting his whole body but we've locked the hips in place so they don't move and so his upper half doesn't quite go into alignment for the attack anymore so he's kind of attacking off to the side so here's how we fix that pretty easy so i'm going to go back into my animation blueprint and in bp this is where we just were i'm going to click back on that green node where we blended the bones and there's a little checkbox that says mesh space rotation blend and i'll just turn that on and i'll hit compile and save and let's test it now so again if i turn the camera so he's facing right at us and i press attack you can see now he's attacking us and basically what happened is it added a little bit more rotation to his upper body to account for the fact that his hips aren't moving anymore so now the attack should line up okay cool so we're almost done one problem i want to solve now is he'll start the attack animation as quickly as you can click the mouse like this so you can make it look like he's angry he's kind of shaking a stick you crazy kids but obviously that's not how we want our game to play so what we want to do is delay it so you can't attack until maybe a second later or maybe we tell it to wait until the animation is done it really depends on how you want your game to feel but here's how we set that up let's go back up into our blueprints bp third person character and right here this is where we just were a few minutes back where we set up the left mouse button to play the montage i'm gonna put something in between this called do once so we'll just put that in between okay and what this means is once the action happens it kind of closes the gate you can't do it again but we want it to reset after the animation plays so what we can do over here is grab a node called delay and the duration of the delay can be whatever you want in seconds so let's say we want the duration to be 0.5 and what we do is once this delay is done once it's completed it goes over here and resets this now we've kind of got visual spaghetti it's kind of hard to see so quick little unreal engine tip if you double click these lines you get like this extra little node to help you spread things apart make it easier to see okay let's press compile and save and we'll press play to test it out now you can see i can't just spam the button and it doesn't even have to finish the whole animation but it has to go at least half a second let me show you one more little variable if it's important to your game that the animation actually finishes before you can do it again you can actually plug this return value from the animation montage into the duration and that just makes the delay equal however long the animation is so if the animation was 10 seconds long your delay would be 10 seconds let's press play compile and save and we can see it's a little bit slower now the animation has to actually finish before you can do it again so if you want kind of a slow ponderous game a lot of times survival horror games are kind of like this because they want to make it actually hard to fight all these zombies make it feel like real life so it really depends on the type of game you're trying to make all right one last thing i want to show you if you did download a whole bunch of animations i want to show you how to make it play all of them uh randomly okay so to add multiple animations to the attack list i'm going to go to my blueprint i just need to duplicate these ones here for each animation that i have so i've got five of them so i'm going to click ctrl d notice it's got this little node here that helps us organize that's nice and for each one in the anim montage i'm just gonna pick a different one so that's number two this is number three this is number four and this is number five and i want each of these to also reset that do once node so i'm just gonna feed this into reset at this point we're really getting some spaghetti here so if you have more experience with blueprints in unreal engine and you know a better way to organize this leave us a comment because i really i really need to know if you do know blueprints a little bit you'll see that this isn't really going to do anything because right now this do once node is only feeding into one of the montages so we need a way to randomly pick five of them so between this montage and the do once node i'm gonna search for a node called multi-gate let's plug this do once out into the multi-gate and then here this first one is going to go into our first montage second one goes into our second montage we can click this little plus sign to add more so let's go up to five perfect i'm gonna plug these in and then last little thing on the multi-gate i'm going to turn on is random so it doesn't go in order and i'm going to click on loop so when it gets to the end of the list it doesn't stop it keeps going back around at the beginning and we should just be able to hit compile save let's press play and see what it looks like so there's one we got different we did like a sword bash that's pretty cool a little punch in there like a lower swipe and then like a really aggressive low swipe and it'll never play in the same order oh it looks like i've got a delay on there i don't like so let's go ahead and press escape and what i'm actually going to do is i'm going to change my duration for each of these to a number that's shorter than the length of the animation because it's kind of slow let's do like um three quarters of a second so i'm just going to alt click type .75 into each one and let's see how that feels so now you can attack a lot quicker again this is just personal preference whatever you want to set it to is up to you all right that's it not too complicated now he doesn't do any damage when you attack and there's really nobody to attack so if you want us to get into that leave a comment below and let us know and if you use this swordpack in any of your games or films or anything like that be sure to leave a comment post on instagram tag us post it on our discord and let us know all right later creators i'm going to keep attacking these boxes here
Info
Channel: ProductionCrate
Views: 70,003
Rating: undefined out of 5
Keywords: motiondesign, motiongraphics, aftereffects, compositor, visualeffects, adobeaftereffects, motiongraphicsartist, motiondesigne, postproduction, videoediting, videoeditor, filmmaking, filmmaker, production crate, productioncrate, footagecrate, footage, crate, Stock footage, free stock footage, adobe, After effects, adobe after effects, special effects, vfx, visual effects, fx, tutorial, tutorials, hitfilm, hit film, hit, film, unreal engine, unreal engine 5, unreal engine v, ue5, uev, unreal engine animation
Id: X1LOpSQcRPs
Channel Id: undefined
Length: 17min 2sec (1022 seconds)
Published: Mon Aug 15 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.