How To Make Melee Combat System In Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello in this tutorial i'm going to go over how to write a combat system inside of unreal engine 5 so my character is currently holding the sword and if i attack this dummy character with my sword enough times it's going to take damage and eventually it's going to die so to get started we're going to import the animations that we're going to use to help us build our combat system so we're going to go to the mannequin folder and go to the animations folder and we're going to briefly close unreal engine and in the link of this video i'm going to leave a link where you can download all these animations so you just want to select all these animations and drag them into unreal engine and for the skeleton you want to select the u4 mannequins accountant and click import all and this will import all the animations that we're going to need to use to build our combat system then we want to set all of these animations and right click on them and go create and create an animation montage we need to make these animations animation montages because this is how we're going to reference them later and if i just head inside one of these animation montages next to it it will say default group because this montage is currently a part of the default group slot and in order to reference and place this animation inside of our third person animation blueprint we need to head inside there and we just want to click on default and go to the animation graph and then we just want to drag up here and look for default slot and hook this into here and as you can see this lock name is default group default slot and inside for montage that is the same default group default slot so we just need to add this to our animation blueprint in order to reference and play these animation montages later now that we've imported the animations that we're going to use in our system the next thing i'm going to do is import the weapons that we're going to use inside of our combat system so i'm going to create a new folder and i'll call this sword and again we can head inside here and briefly close on our engine and again i'll leave a link in the description of working down with the sword and this all texture for the sword the way you want to import it is just drag it in and then we want to import this as a skeletal mesh so you can use a different um model if you want to but just make sure that you import it as a skeletal mesh and click import and then we can just import the texture that i'm going to use for my sword i'm just going to apply this texture to my sword so to do that i can just right click on the sword texture and create a material out of it then i can head to my sword mesh and then i can just select the sword material that i just made and it will apply the sword texture then we can close this and then you want to go to your weapons skeleton somebody's called sword skeleton double click and open it up and then you want to select the skeleton so this scanner is called cuban scor003 you just want to go add and you want to select add socket and you just want to double click this first socket and call it start if your socket is looking really big like mine we just want to change the range of scale here so i'm going to change the radical scale to be 0.05 in all of those axes and then we just want to select here selecting translate objects and move this to the start of our sword or your weapon that you're using then we're going to select the skeleton again and go add add socket just double click here and call this end we'll make the range of scale this 0.05 and all its axis as well because it's really big and then we just want to move this to the bottom and then we can click save next we can close this next we want to make it so that when the player character is holding the sword that they're holding it correctly and it's in the correct position so to do that we can head over to the mannequin folder and go to the character go to the mesh and go to the formatting skeleton we want to go to a preview animation and you just want to preview the sword slash animation because this is the animation character is going to do on the holding sword and we can just pause this and i'm going to go to the first frame and i'm just going to select here his hand are right click and go add socket i'm going to double click on the socket and call this my sword socket so this is going to be the socket when i play character holds their sword or the weapon that they're going to use we can right click on here then go add preview asset and you just want to select the sword that we just imported and just move it so this sword is in the player character's hand so we can see mine's a bit off so i'm going to move it so it's exactly in the black out of his hand and you can rotate it a bit because mine's a bit in the guy's head and if you're not happy with the scale of it you could scale it down here so i think i'll make mine 0.7 in all its axis okay and i'm happy with that so we can just go save and now that we've set that all up we're ready to start coding our combat system so to get started we're going to go to the third person bp because of the blueprints and the third person character you want to head to the event graph and we're just going to right click and look for right mouse button we're going to create a simple combat system so i'm not going to create something too complicated it'll be like the one shown in the video so when we press the right mouse button we just want to drag off pressed and look for do once and then after completed we want to look for play animation montage and we want to play the slash animation montage that we made at start so the sword slash then we can drag up here and look for delay and hook this return value into here so this will get how long this animation is then we can hook up this delay into the reset and then we can just double click here to make it a bit tidier then we just want to go to the viewport select our mesh and go add and then look for skeletal mesh and then we'll make sure that this scaled match is a child of the mesh if it's not just select the scale too much and drag it into the mesh so i'm just going to do that because it just under what i did and then for the scalpel mesh um for the parent socket we just want to make this the sword and then fill the skeleton mesh we want to select our sword and if you're still still in the correct location just click on these arrows here and i'll make it so this was in the correct location so now i'm just going to compile and test this out just test that everything works so far selecting the right mouse button my character does that slash attack next we're going to make it so that when the player character does their sword slash we're going to use a line trace system to see if the player character hits anything with their sword so to set that up we can head to our third person character and go to the event graph we want to find some free space and right click and look for add custom event and we're going to call this trigger sword and what we're going to do when we call the trigger sword event is basically do a line trace in between our sword to see if we hear anything so off of the trigger sword we just want to drag and look for set timer by event and we just want to right click on the return value here and promote it to available and call this trigger sword event for the time of this event we want it to be 0.01 seconds we want to check this looping box this will just mean that we'll do the event every 0.01 seconds and for the event that we're going to do we just want to drag off here for add custom event i'm going to call this sword line trace so every 0.01 seconds we're going to be doing a line trace from our sword to see if we hear anything so we just drag up here for line trace by channel where this is going to start we want to drag in our scalable mesh and i'm actually just going to select the scaled mesh and rename this sword so it's a bit clearer and we just want to drop off the sword and forget socket location i'm just going to do this and if you remember inside of our sword so i'm just going to head back to my sword skeleton we made two sockets start and end so we're gonna be referencing and we can get to our line race between the starting and ending points of our sword so here the first and second location we want to get is going to be called start or whatever you called your starting socket location and we just want to hook this up into the start and then we can just duplicate this so i'll press ctrl c and ctrl v and where our largest will end here in the socket name we want to have it be called n because that's what we called our ending socket and we want to hook this up to end and for the trace visibility just change this to be camera and for the draw debug just change this before duration then we just want to drag off the r hit result so let's suppose we get the data of anything that we hit with this line trace we just want to go break hit result click this arrow and then off the hit actor we can just drag up here and look for apply damage and then hook this into here and we'll make it so it does one damage anytime we hit something just so that we can see that the system's working and everything just right click and go event begin play and just hook this into here so we'll just test to see that it's doing good nightmares for our sword so let's go compile and go play and you should see that um line trace going between your sword so just make sure that's happening next we'll head back to our third person character and we can delete this event and play so we're going to call this trigger sword event when the player character swings that sword but we also want to event to cancel the slide trace when the player is not swinging the sword so to set that up we can just right click and look for add custom event and call it stop trigger sword and what we can do to end this event is we can drag in our trigger sword event get it and then drag off here and look for clear invalidate timer by handler and this will just cancel the event here so now we're going to set it up so i want the playercat to trust that swinging sword animation it will trigger this event and when they stop doing that animation it will start training the sword event so to set that up we just want to go compile here close this and in our blueprint folder we'll just right click go for group and class and select notify we're going to look for anim notify state so select this one and just go select and call this sword event and we want to head inside here then we want to head over to functions go to override and select receive notify begin so we're going to make it trigger this notify and when it begins basically we want to trigger the um trigger sword event you'll see how this all fits in when we apply this to our animation but for the time being we want to just drag off the mesh component from here we can get the owner and from here we can cast to the third person character or whatever your character is called and then from here we can trigger the sword event so we just want to drive here and a four trigger sword and then hook this into here then we want to go to the functions again and go to receive notified end so when this notifier ends we will drag off the mesh component get the owner from here we can cast to the third person character hook this into here and then we can trigger the sword over event so stop trigger sword and hook this into here and compile so that we can reference and use this um sword event we need to head over to our mannequin and go to the animations and then we want to go to our sword slash montage and we want to go to the tab notifies and we just want to right click and go add notifier state and then we want to add the sword event that we added and then you just want to find a position in the animation where you want the line trace to start so let's say i'll make my elantra start let's say here so i'm just going to drag this so it starts here where one and we can drag this all the way here and where the two event is that's where the sword laundry is going to end so i'll end mine here and we can go save and we can just test this out so if i just close this and go play we can see that when i walk around then the light races however if i do the attack animation it does a line trace so we've set it up so that one player does that specific animation it will do a line trace next we just need to set up a dummy character who my player character can attack and kill so to set that up we can go to our blueprints and go to blooper class and select character just call this guy dummy head inside here for the mesh we want it to be the sk mannequin and we just want to move this down and rotate him minus 90 so he's facing the correct action for the animation blueprint we just want them to use the ue4 mannequin sorry the third person animation blueprint then we want to head into the minecraft and if you remember in our third person character we made it so that we apply damage to whatever we hit so dummy is going to need some health so under variables just create a new variable call this health and change this variable type to be a float and just compile this and then we want to right click and look for event any damage so this will be triggered when the player character damages them here and event any damage we just want to drag up here and therefore do once and then we want to get the amount of health that the dummy has let's make it so the dummy starts with say three health and then we want to subtract to look for subtract i'm going to subtract it by the amount of damage that they took so i'll just hook from damage into here and then we'll set it so that their health is um and then we'll set it so that they have a new health of whatever the health is minus the damage that they took and then we're going to check to see if this value is less than or equal to zero so we'll just drag up here and a full branch and hook this into here and if that is false then what we're going to do is look for play and montage and the animal touch that we're gonna play is going to be the hit reaction montage then we just want to drag up here and look for delay and hook this into here and hit from completed into reset and i'm just going to double click here just to move it down so if our enemy is damaged and they still have more than zero health then it's just gonna play a hit reaction montage however if the player is damaged and they have no more health then we're just gonna drag up here and look for play and on montage and we're gonna play the death montage and we're just gonna go compile and one more thing with our death montage just so it doesn't look weird we want to go to browse we can click this browse icon it will take us to our animation and we just want to go to the dev montage animation and then under asset details under search details we will auto enable auto blend out and just leave this unchecked and save that and that will just make it so that when it plays the animation it doesn't loop back to its original position so you just want to make sure that's checked and then we can drag in our dummy go play and hit my dummy let's say three times with my sword he'll react for him the third time he's gonna die and although his death animation so with that we've set up a mean attack system i just prefer the system because it uses a line trace and i think it's a lot more accurate than the old system that i previously made so that's all for this tutorial if you enjoyed like and subscribe to help share the video and i'll see you guys next time bye also bonus tip if you want to play player character can't move when they're doing their attacking animation you just want to head over to the animations folder and find your attacking animation so mine's called sword slash and under the details you want to look for root motion and just enable root motion and go save and that will just make it so the player character can't move when they're doing the attacking animation
Info
Channel: Unreal University
Views: 132,529
Rating: undefined out of 5
Keywords: How To Make Melee Combat System In Unreal Engine 5, unreal engine melee combat, unreal engine melee combat tutorial, melee, unreal engine, unreal engine 5, ue5, combat, how, to, Uisco, tutorial, combat system, sword, fighting, damage, enemy, ai
Id: iPfU1SmzkkY
Channel Id: undefined
Length: 16min 59sec (1019 seconds)
Published: Wed Feb 16 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.