How to build a simple combat system in Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] what's up guys I'm back with another video here unre Engine 5 tutorial today is going to just set up a very very very simple um combat system um where we'll show how to play the animation where we can apply damage as well and you know what on top of that I'll even show you how to um retarget um animations from mixo to the um uee mannequin okay so I'll just leave the link in the description for this okay so click download download with skin and then once it's downloaded hop over into your project U I'm just going to create a new folder here um and I'll just call it um anims for now doesn't really matter um for the sake of this video double click I'll open it up and then I will let's refresh bring in my animation make sure the skeleton's none because we're bringing it in with its own skeleton so we can retarget okay so import all no problem cool says punching one anim ximo so this is the animation itself you right click go to retarget animations this window will pop up this is really really easy guys in Unreal Engine 5.4 just click make sure this is the original Source punching and we want to Target it to ourmore man and all we have to do is export retarget now we want to click on the animations and we want to export the animations um want to export override existing files export done now when I open it up you can see it's working on our Manny like so really really simple to do okay so that's how you um retarget the animations okay so what I want to do is set up the combat system okay so what we'll also do with our animation sequence is we'll right click we will um create an anim Montage just going to call it punch and with the punch um I'm just going to show you as well so we're going to set up what's called an anim notify okay so we's just stop here I'll explain so when the punch is I want this is when the punch is going to cause damage so say from about here yeah here yeah and the notifi track just right click add notify add new notify call it um T red ready let's move it up a little bit and then when the punch is finished doing damage he's pulling back there let's do add notify again new notify attack not ready all right so basically what we've done is we've set up notifies so now from here the tech ready is when we're going to cause actual damage to the health of our enemy and then this is when the damage stops being inflicted all right it'll make sense in a second but once you've done that just press save close it down we're not going to need it anymore if it's done right should be fine okay so let's start by going to our third person um blueprint double click open up the blueprints third person character blueprint let's go to the viewport that was the right punch yes so click on the mesh um and then press add in the components we're going to add a sphere Collision just going to call it attack or I'll call damage actually this is the damage sphere um I want to socket it to the right hand so Hand handcore R like so it's far too big so I'll press R to rescale it press W let's put it down about here works for me um now just make sure it should be overlap old Dynamic on the right hand side yes then go to the evance O component begin overlap okay now in here is what we're going to do is we're going to get the apply damage the other actors are damaged actor then the amount of damage we're going to cause let's say 0.25 yeah oh 0.25 and then what we want to do is we want to run a delay hold down D left click for quickness 0.2 seconds is fine and then what I want to do is I want to run off here a print string of the value so it'll just tell us the value okay that once once it's um created the damage okay so I press compile just leave that for now okay and we're going to create our enemy okay so what I'll do is I'll just right click in here I'll go to blueprint class we'll create a character we'll call it enemy aior BP we'll double click we'll open this up um we get a skl Mion here we'll get the Manny the U for mannequin let's get the anom class for it uh which one is it is it this one yeah that'll do and I'll press e to rotate rotate it around 90 press W bring it down there we go all right cool right so basically what I want to say is in the third person character this damage node okay is really good for applying damage okay now to receive the damage we need to go to the event graph of our character blueprint so it's our enemy character blueprint right click type in event any damage all right now this damage here from the green socket the float value is this value here all right cool so once we get the damage what we want to do is create a variable anyway for our health so just go to V variables call it health change it to a float um compile top left then you get a default value we'll give it a value of one just compile so it's set there we'll then get our health we'll also subtract our health add the damage so the damage is subtracted from our current health and then we're going to set the new value so set health so the difference if anyone doesn't know the difference between get and and set is basically um you're getting the actual value of what it is so it's one as you can see oh it's one then we're taking away the damage from our apply damage from our character which is 0.25 and then we're going to set it to its new value so that's the difference between get and set get is the current set is the new values all right right now once that's done I want to print string just to make sure that it's working all right press compile um we need to go back into the third person character actually and what we're going to do is we're going to cast this to enemy AI cast it to the enemy AI like so make sure you join it up properly and then what we want to do is we want to get a branch hold down the b key we're setting up a condition basically all right the condition is going to be attack ready okay so so set attack ready so make a new variable make sure it's a Boolean just call it attack ready all right so get it make it the condition um and then if it's true we wanted to just do once like so when completed apply the damage and from here we want to come all the way back and reset double click to reroute just so we can keep it all tidy like so now we still haven't set this up for the attack notify all right so remember we set up in the um animation Montage okay so we will go to our animation blueprint of our player blueprint okay so go to characters go to the mannequins animations abore Manny double click it open it up okay now it's a bit different in here okay because obviously you're not going to use the Manny when you're building your game all right but it's sort of the same principle okay so what I'm just going to do here pull this out all right I'm going to run a uh sequence okay so we have it like so and then I'm going to just drag off here I'm going to cast the third person character yeah make sure the objects joined up to the get owning actor and then from here I'm just going to scroll down into space or drag this down into space set tack ready um you're going to need another one oh bring it down here set attack ready again and then right click type in attack ready and you'll see event anom notify attack ready Jo to the top one make sure you take the box and then right click attack not ready and join it up make sure it's false okay you press compile and now what we need to do jump back into our enemy um actually we don't need this print string okay so it's fine just delete that all right press compile go back into the blueprint okay make sure that you cast to the enemy AI all right um because now our attack ready is set up here for um our animation blueprint for these okay so this all makes sense now all right now one more thing to do two more things to do actually we'll need an event tick to run it to make sure it's working so event tick in the third person character blueprint just join it into the cast enemy AI like so and also you'll want to right click I'm going to use the left Mouse button so left Mouse button if it's pressed you want to play on a montage ours is a punch obviously yours will be whatever this is the simple way to do it um we press compile um bring your enemy into the scene like I have press play now we'll run up here and I'll punch see it's saying hello hello hello okay one second so it's just the wrong way around so if I open up the third person character blueprint excuse me and I go back here um yeah so I don't want this one okay so we'll delete that one all right thr these up go back into the enemy Ai and run a print string just because we haven't set up a health bar or anything for the enemy not that you know we have to press play oh let me just hit these three little dots play a new window editor like so run up to the enemy punch him says hello still it's not supposed to stay hello one second uh supposed to do the hell value one second here that's right let's compile press play there you go so I've hit his health I've tooken it down from one to 0.75 now it's a half now it's a 0.25 now it's a zero so he should be dead really so what I'm going to do let's just run a little ragd doll in here okay so I'm going to show you how to do a de function as well so in our enemy AI right click custom event add new custom event call it death okay so basically what we want to do is we want to get our health and if it's less or equal to zero creating a branch what we want to do is get our character movement or is it mesh sorry set simulate okay no sorry my apologies so what you want to do is you want to get the mesh get the mesh set simulate physics make sure you simulate it and also if you go to the if you click on the ma uh the captal component scroll down to the Collision presets where the hell is it oh it's Pawn sorry if you click on the mesh and it's character MH change that to ragd doll in the Collision presets press compile let's go test it out so let's do it head- on one 2 3 4 five six oh guys I'm so sorry okay so now we've created our custom event basically you want to run it now here so death so you call the function death press compile Press Play One two three four and he's dead all right that's it guys very very simple okay so we set up a death function we've retargeted animations from miimo into unreal 5 with the click of a button it's pretty cool new feature uh We've also set up how to apply damage and event any damage as well and we've looked at um event um anom notify States as well okay so that's it there's your simple combat system really really easy to do um please um like And subscribe for more videos on Unreal Engine 5 um thanks very much don't hesitate to uh leave a comment in the comment section goodbye [Music]
Info
Channel: Brianko Games
Views: 1,271
Rating: undefined out of 5
Keywords:
Id: lIUHq8UsQQI
Channel Id: undefined
Length: 16min 16sec (976 seconds)
Published: Mon Apr 29 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.