Create Dynamic AI with Motion Matching in UE5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys want to create AI that switches States using motion matching welcome to Unreal made easy today I'll show you how to set up animations blueprints that can be used for AI and player characters first we're going to cover the setting up the animations next we're going to create an AI blueprint and then finally we're going to complete the motion matching animation blueprint okay so let's not wasting time and let's begin okay so in order to start our AI motion match project the first thing we're going need is some animations and we're going to snag them from the actual L project and inside this project we're going to create the actual motion match folder and then transfer it to our our you know third person fresh project so okay so now that you've installed and opened up the project we're going to go to our content folder and what we're going to do is we're going to create them our motion match folder here so let's go ahead and start by starting a new folder called a motion match and then from this point we're going to go and grab select animation so to get those animations we're going to go to characters heroes the mannequin folder animations and we want this Locomotion right here so the two that we want are going to be the unarmed so we're going to hold down control and left click we're going to also uh hold down control and hit left click on the rifles so we have both of those select and then over here in the project we're going to scroll to the very bottom and we're going to scroll up slowly until we find our motion match we're going to left click hold drag and then place these two into there but we're not going to move here we're just going to copy here so we can leave our L project in tag so we can copy here yes we're going to do all of the animations there and yes we want to verify we're sure okay now let's go ahead and go back to the top of the folder go to the content folder go back to our motion match and you can see we've got our two copies of our animations we're going to use now we're going to clean this up a little bit before we send it to our project so first thing we're going to do is we're going to hit the filter button we're going to go to animations and we're going to select the blend spaces uh and the blend space one D and we're also going to select the animation blueprint cuz we won't need any of those so let's click out of here do a left click do a control a and then uh a delete and yes we can go ahead and delete those animations there next we can go ahead and go ahead and clear these filters so we just hit the reset filter here and then we're going to type in 180 cuz those are going to be all the turns we're not going to need those so we're going to left click again contrl a and select delete yes we're going to delete everything next we're going to grab the pivots same exact thing a control a and delete because we won't be using the pivots as well delete all those and then we're going to also grab I want to say the enter no entry so we won't need these entry uh animations we go ahead and delete those nor will we need the exits we can go ahead and delete those next we're going to look at the the idol and we can do a control a or wait to do a left click and then a control a and what we're looking for here is anything that says scan we want the Crouch animation so make sure we hold down control do a left click and we're going to keep our let's see Crouch animation for the rifle and we also want to keep our Crouch for the unarmed and we also want to keep anything that says scanned so we're going to look for that so get the hip fire fidget so here's the the scan right here we're going to keep there's only going to be two so there's this scan here then let's see and the other scan here and then we can go ahead and select delete so we've deselected the Crouch both the crouches and the the idles for the Crouch and we also deselected the scans so we're going to go and delete Force delete now when you're done you should have all of these here okay so let's go ahead and do a control shift s oh I almost forgot so one more thing we're going to grab is over anything that says over drive let's see so this uh yes yeah we can delete all this so just type in over yeah the override poses we don't need these we can go ahead and get rid of those and force delete okay so now we go back to our motion match folder here right click it and we're going to select migrate now we can go ahead and deselect the characters button here and we're going to scroll all the way down as you can see here we don't need the effects either and then we do want to keep our motion match folder we just created scroll all the way down to the very bottom and we don't need this physic material folder as well select okay okay so you want to find out where your project is and put it into your my into your my project or whatever the name of your project is select the content folder make sure the content folder is selected here and hit select now once you're back into your third person project we're going to go ahead and open the folder up and then right here we'll see we've got our folder within the project now before we continue we're going to have to actually enable the plugin so let's go ahead and uh we're going to do two things here we're going to go to edit and we're going to go to editor uh preferences and then right here in the general appearance right here under asset open location we're we're going to change that from a default to the main window so that way we're just opening up tabs instead of opening up brand new tabs on top of each other then we're going to hit the edit again but this time we're going to go to the plugins up here all you have to type is uh t r AJ and that's going to give us our motion match trajectory uh plug-in click yes and make sure it's checked and then we're just going to go ahead and restart our project okay great now that we're back in our project we can go ahead and close that plugins folder and now right here we're going to open up this motion match folder fer we're going to right click and we're going to create our assets now so we're going to go to animations motion match as you can see here we've got three different ones we're going to start with the POs search schema and we're going to use our skeleton so we're going to do the skeleton here so P SS underscore and that's going to be called Manny control shift s we're going to now okay before we continue something else to note is that while we've got our animations here we're going to have to as you can see we've got them here we're going to go back this motion match folder here we're going to need to go into the filter here one more time and we're going to go to animations something I forgot to do and we're going to go to the animation sequence which is going to give us all of our animations we're going to left click do a control a and then we're going to right click on one of the animations and we're going to replace the skeletons because when we export it we really just only grab the animation so let's go and replace the skeleton skeleton we're going to use is going to be the same one we're using throughout the project which is a default just do a left click and hit okay and then as you can see right here in the lower right corner it says 15 unsaved that's fine what we want to do is we're going to do a control shift and S and and that will resave all of our animations so now we have a skeleton attached to the animations we can go ahead and left click here and reset the filter okay continuing on so we're going to rightclick go to animations folder again or animations go to the motion match and we want to do the post search normalization set so we're going to do p s and sore we're also going to call this Manny just to keep it simple control shift s then finally we got to do the animation motion match the post search database now we're going to make S several of these and we're going to use the post search uh thing we just made the schema from earlier so here we're going to do PSD underscore and we're going to call this Bas because that's going to be our base movement control shift s so now with this highlighted we're left click and highlighted we're going to need to make five more of these so let's just go ahead and do a control D and then hit enter contrl D hit enter that's contrl d as in David or dog enter control D again until we have five of these now we've got our base movement but now we need our base Crouch so we're going to highlight this one here for the first one we're going to do an F2 and we're going to going to go ahead and name this Crouch continuing on we're going to do the jump now now we're going to need the actual rifle base so we're going to need the rifle base so we're going to do a uh F2 again and right in front of the base we're just going to type in Rifle and that'll give us our basic walk for rifle then we're going to need hit F2 again and we're going to need the rifle Crouch that's going to be important as well hit enter Then F2 again we're going to need finally the rifle jump no I'm sorry yes jump need the rifle jump and hit enter okay so now that that's done we're going to have we need to make one more thing here we're going to need our animation blueprint so that's where we're going to for our AI here so we're going to use the same skeleton we're going to create it and we're going to do ABP pcore and we're going to call this AI rifle so that way we know that is our rifle blueprint control shift s to save that so we've got all our assets here we're going to go to the content folder go to third person go to Blueprints and we need to duplicate this third person so we're going to do a uh contrl D to duplicate let's left click contrl D and we're going to call this BP which is the blueprint um rifle AI actually I could of let me change that I think uh we're just going to do BP uncore Ai and then rifle that seems better and then what we can do here is we're going to go ahead and open that up so we can go ahead and start to create our character blueprint now for this one here you don't need you don't need the the camera so because this is going to be our our AI so it doesn't need the camera or the boom select both of those and then just go ahead and you can delete those however we do need to make two components and the first component we're going to need is the TR r AJ which is trajectory component hit enter and we're also going to need see it's going to be the sensing so we need the pawn sensing component as well hit enter we don't need any of the logic in this blueprint so we can go ahead and delete that and then we're going to make two quick variables here so we're going to do a we're going to call it the we're just going to call it the Char uh Crouch so that's the character Crouch and we're going to use a question mark because it's Boolean we're going to ALS o add a Char weapon mode and hit enter and we're going to change that to an integer and then we're going to select our mesh right here and we're going to switch our animation class to the blueprint we just created which is the AI animation blueprint rifle and we're going to compile and save and then just for the of it control shift s and that'll save it again okay continuing on we're going to need to make uh some custom events so we're going to start with three of them so we're going to do a custom we're going to add a custom event here and while we're at it we're going to let's see we're going to duplicate this so highlight it do a left click and highlight it okay so in order now we're going to need to duplicate this like I said about two more times so we're going to do a hover the mouse down here contrl D well first make sure we highlight it contrl D and then we're going to do it again contrl D again and then we need to rename these so for the first one we're going to call this our base mode the next one will be our rifle mode and then the final one will be our Crouch mode and then we're going to do a compile and save now all three of these we're going to need again but we're going to have to rename those as well so we're going to go ahead and just to make things simple highlight all of them go down here a little bit to the bottom contrl D and we're going to go ahead and just name those real quick while we're here so the first one is going to be random base walk the next one's going to be rifle I'm sorry random rifle walk and then finally we're going to do a random Crouch walk and we're going to compile and save that as well now let's go ahead and go back up here to the top now we're going to need to use our variables so we're going to hold down the control button and for the Char Crouch we're going to put one right here oh sorry hold down the alt button and left click and drag and drop the Crouch so we're going to drag and drop the Crouch here now we're going to change the speeds for each of these as well so we're going to or we're going to change the mode so let's go ahead and uh grab that as well so it's alt and left click here as well and we're going to connect all these up for the Crouch we're going to set that to true because we will actually be crouching but whenever we're walking normally we'll set it to false to have us walk regularly next we're going to grab our movement component put it right here and what we're going to do is we're going to drag off of here and we're going to set max walk speed okay we're going to left click on that and then we're going to hover up here contrl dtrl D again now remember you're going to need to Target the movement in all cases here so we want to make sure those are all hooked up oh that's my fault there we go and then we're going to hook those all up now for our walk speed so we're going to set the walk speed to 300 we're going to set the rifle mode into a run so that's going to be 500 and then for the it's going to be a little bit slower so we're going to do that 200 compile and save okay now right above here we're going to also add it a begin play because we want our character to start walking the AI to walk at the beginning of the level so we're going to do an event begin play and then right off here we're going to drag off and we're going to grab that random base Walk So at the beginning we'll do a random base walk walk all right and that should cover that so now let's go ahead and work on our our our our walk States here okay so now that we're here we're going to need to as we do our random Walk we're going to go straight into our modes our random walk mode so we're going to do random uh base walk here for this one random rifle walk here random Crouch walk here all right let's go ahead and give them some space here all right do a compile and a save and then right here we're going to we're going to do a AI move to node which is going to look like this one right here we're going to stretch this out here just a little bit and then for the pawn we're going to say it's ourself so and then we're going to need a dust destination that's going to be a say I want to say reachable I'm trying to remember okay yeah it's going to be a random I want to say random reachable yes we're going to get this random reachable State here and again I want to move this over just a little bit because we're going to reuse this and then the origin is going to be we're going to get actor location okay now we're going to select all this actually let me clean this up here we're going to select all this here go down right here do a contr d and then we're going to do a contr d again here okay that looks good so now we need to just make sure we hook these up and then while we're here we're going to go ahead we can just neaten that up a bit now on success we're going to have it cycled back and we're going to do a see we're going to do a random we're going to do the random base walk again and then after this we're also going to do it here as well so contrl D and then finally we're going to add a jump here so we're going do a regular jump there yeah I'm going to switch that around so we're going to hold down alt disconnect that disconnect that we're going to have a jump on completion first and then going to repeat the cycle so it'll only jump like once because if we if we do it the other way it'll just keep jumping continuously so we're going do a compile and a save okay so now we're going to need to use our Pawn sensing so we're going to select the left click this and we're going to scroll down until we see on C click that and then for this we're going to go right into our rifle mode so let's go ahead to our random rifle walk cuz we're going to start running with our rifle and we're going to do that with an AI move tube node and then for this case here let's see we're going to Target the actor that's who we're going to follow and it's going to be our self again so we're going to use ourself then on success let's see okay so on success we're going to do a print string and we're going to change the color to red and we're going to change the text here to bang Bang You're Dead so AI will say that letting us know that he shot us and then after that he's going to jump then after he jumps he's going to going to crouch walk going to random Crouch walk compile and save okay and that's should cover it for our blueprint here so we're going to go ahead we're going to select our mesh and we're going to open up our animation uh blueprint that we made earlier so go into the animation class the one we selected earlier we're going to browse to that folder double click the open it up now we're going to start in the event graph get the try owner and we're going to have to grab the blueprint IIM initialize animation and what we're going to do is we're going to drag off of here we're going to cast to the blueprint of the AI rifle because that's going to be our AI so we're going to cast to him or her or that person depend how you look at it drag off here we're going to promote this variable and we can keep it as it is so we can use that variable that we just created form down here drag it here do a get we're going to go ahead and compile and save and then the first thing we're going to grab is the trajectory so we're going to get trajectory so we're going to get the trajectory and then we're going to promote that to a variable and connect that up next we're going to get movement and we're going to line it up we don't need this part here we can connect this up we can now promote this as well connect it up then here let's see oh actually we're going to pull off of here again and we're going to type in is falling cuz we're going to get the falling movement from the blueprint so the character is falling we're going to promote that to a variable as well and we're going to say in the air so in air is fine with a question mark enter connect that up then we're going to get Crouch and then we're going to also promote that to a variable and then finally we're going to get our weapon variable so Char weapon Char weapon mode grab that and for the final we're going to promote that as a variable as well okay and we're going to compile and save next we're going to go to our animation graph and then what we want to get is motion match and we're going to grab the one under the post search here we're going to use this here to make a select and what we're going to do is we're going to plug in our weapon to the Wild Card make this nice and neat now we're going to need this particular situp two more times so we're going to highlight it right beneath it we're going to do a control D and then one more time down here contrl D okay move these a little bit we can move them a little bit closer to each other okay so to start out here we're going to need to do a blend bull so blend poses by bull now for this we're going to need this to go to the false not the true we're going to do while that's highlighted we're going to control D do that again and we're going to add it to the false as well right here and then right here we're going to need to add the pose history which is right here and then select this by right clicking it go to the bindings character trajectory select that and yeah we can hook that up next we're going to add a default slot and I do this just in case you want to add your own um you know attack animations or dance an whatnot we can we can move this right here connect this up okay so now it's going to be important that we hook everything up but before we do let's go ahead and add the different things we need so for the start of it we're going to need our base walk and our rifle base walk so we're going to go to the rifle see rifle basee next we're going to go to our Crouch so we're going to get the base Crouch oh sorry that should be up here so rifle we're going to do the base Crouch right here and then for the rifle Crouch we're going to do that right here so make sure you select that so you got so anything that's zero is going to be that's the mode for the basic and then the one option is going to be the rifle so then up here we're going to need the jump as well so we're going to need the base jump and then we're also going to need the rifle jump which is right here so base and rifle jump base and rifle Crouch and then base and rifle walk now for the Crouch we're going to just go ahead and hook that up so if it's true we're going to activate that condition through the chair the car to crouch same thing with this with the jump we're going to set that for True right here and to activate that we got to be in the air right here and then make sure you do a compile and save okay so the blueprint and the these animation the these two are done so we can close out of that for now we really won't need that now so and just to make sure okay we see at the bottom we're all saved up we're going to content folder now we're going to need to we're going to need to open all these so we're going to have to add the animations to the databases so we're going to do a uh left or a left click here hold down the shift button and we're going to grab anything that says PSD and then oh we can make sure you don't add that just PSD right click and then we're going to select the edit now to keep things simple we're going to start with the the jumps so we're going to go with the base jump first here we're going to go into we're going to type right here we're going to type in Jump Loop and then what we want is we're going to open this up on the left here we're going to get the unarmed jump so yeah we're g to check grab both of these I just I'm just doing a left click control drag that up there we're going to hit save go to the rifle jump and we're going select the rifle folder that's going to give us those Loops do the same exact thing drag and drop and then as you can see here there's a little star here we can just go ahead and hit save star will go away and then that's how you you know it's save we're done with those we can go ahead and close out of that so we don't need the two jumps we can close those now let's go ahead and move on to the base Crouch same thing Ty in Crouch make sure that you're in the base Crouch and you select the unarmed folder we're going to select the first one do a contr a to select them all left click and drag and drop them all in and that should be good hit save and we can go ahead we can close the base Crouch out so we're just going to go to the rifle Crouch itself and then drag into that it save crol a and just delete that because we put the wrong animations in close that next we're going to okay while we're in the rifle folder we're going to select one control a we're going to grab all the animations from the rifle folder and drag them into the rifle base we're going to remove the Jog and Crouch I mean no I'm sorry the Crouch and jump so Crouch we're going to highlight it same thing delete that jump and delete that so now we're going to go ahead and hit save and now to the base we're going to go to unarmed same thing crl a we're going to drag and drop that and hit save okay now that that's all set we can go ahead and we can close both of these out now while we're in our level here we're going to go up we're going to hover over it like this and what we're going to need is we're going to need to go to our quick ad and we're going to use a nav this is so that way our AI can walk around so grab the nav base bounds uh volume here and then we can hit the the r key and we can expand this out okay span that out hit the W key and then go right here and line it up you know it's best you can then hit the r key again we're going to we're going to shrink the sides down a little bit because it doesn't need to exceed everything we can hit save but hit the P key see highlight it oh select the nav again nav we're going to hit the r key again let's go ahead and zoom into a different position and we're going to expand this up a bit CU we hit the P key earlier see so p is to turn it off P to turn it on and we want to make sure that everything's covered here these are all the places the AI can walk and then next we're going to go and we're going to grab our AI so we can go ahead and go to the content folder third person blueprint and then we can take our rifle person put them out here and then as we're looking at him let's see yes we want him to not face us cuz we're at the start here oh we can go ahead and hit P to take out the thing here but you can see everything here from the Green Line forward is what he'll look at okay I just noticed something that I made a slight mistake on and we're going to fix that so go to the content drawer we're going to open up the blueprint again and right here where it says for the random walks we need to S change all these to the the modes so what we're going to do is we're going to get random we're going to get base mode so we're going to replace that with this rifle mode and then finally Crouch mode compile and save now another thing I need to fix that I forgot about which is right up here is when we're setting our modes we're going to make sure that the rifle mode is in the one mode otherwise we won't switch between states so we're going to compile and save okay another thing I forgot we're going to scroll down here and we're going to need to set the radius on how far the character will walk so I'm going to select 3,000 for all of these so where it says random walking we're going to in the radius select 3,000 okay now that that's all set let's go test it out as you can see the character is walking around and then every time they finished their walk they're going to jump in a regular jump then now they're chasing me because they spotted me so I'm trying to get away and then bang bang you're dead and he walks away crouching notice that now he's changed States into the crouching he's changed States so now after a little while he's going to go back to walking when he finishes walking over there he's going to do a jump just to let us know he's finished with this state and then if I kind of walk over here he's going to see me and Chase me and you see that he's changed states he just he's chasing after me then if I get caught he's going to jump Spang your dead and keep it moving into the next state but notice if he sees me again he's going to keep doing it well that concludes today's video I hope you found this AI motion matching setup helpful and easy to use and uh again sorry about the long video but I'll see you in the next one for
Info
Channel: Unreal Made Easy
Views: 750
Rating: undefined out of 5
Keywords: UME, ume, ue5.3, beginerfriendly, unrealenginemadeeasychannel, tutorial, tutorials, Unreal Engine 5, UE5, AI, motion matching, state switching, dynamic AI, game development, animation blueprints, AI animation, UE5 tutorial, Unreal Made Easy, game design, AI state transitions, Unreal Engine AI, UE5 animation, AI programming, AI motion, game AI, Unreal Engine tutorial, AI blueprint, game development tutorial, Unreal Engine 5 animation, AI state switching tutorial, dynamic animations
Id: GcGHN0IlL1M
Channel Id: undefined
Length: 41min 41sec (2501 seconds)
Published: Sat Jul 06 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.