UE4 Melee Combat Tutorial | Quick, Easy System To Setup

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey fellow game developers and game developer bets is that even a word welcome to my channel and today I'm gonna show you how to create a very simple but very doable melee combat system that you can implement in your games and it works very well in my opinion and it's high performant and it works for multiplayer so I'm gonna show you how to set that up but before we get into it I just got to show you what I'm using so I'm using the Paragon Graystone asset here and I like to prototype with the Paragon assets simply because it just makes things so much easier I don't have to set up an animation blueprint or anything like that and it comes with a ton of animation so it's just this Paragon Greystone just search for it on the marketplace but you might have your own characters and animations already going so just to show you I have the Paragon guy here he has his weapon and we're gonna set up a damage system so that when I swing my sword I damage him and then kill him so let's get into that here I'm just gonna select the mash you want to get into your your blueprint or your your your character here and what we need to do is we need to set up a collision box here so we're gonna we're gonna do damage through a melee legend box so in the viewport you can now see this box component here just gonna drag it out like this I'm gonna turn off the scaling here just so I can get a pretty good pretty good accurate collision here because I want the box to be roughly the size of his swing right these swings I want any enemy that's in this box to take damage it could be multiple enemies one enemy but whatever you want to do I'm gonna do multiple enemies here so that's probably big enough we can actually test this we can turn off hidden in-game here on the right and do a line thickness of two and when I play you'll actually see the box here so let's see when I swing the sword does it accurate it looks like I actually need to bring it out a little bit more I'm just gonna scale it up a little bit more here maybe a little bit wider and that looks pretty good I'll go with that so I'm gonna set it back to being hidden so you can't see it anymore and when we play should be gone okay so the box is gone now so what we need to do is we need to set it up so that when the player actually does an attack it's going to register damage on the player and we do that through an animation notifies state and through the mail a hip box here so what I'm gonna do is I'm gonna set up the collision first okay so we'll just select the mail a box here we'll scroll down to the presets here and we'll do custom will ignore all but we will overlap pawn that's it okay and then another thing we want to do is the way I'm gonna check for the actor that we're colliding with is through tags so up here in class defaults I can type tag we can add a tag here and I'll just add player and now tags are really great because you could also add a tag to your a I and and call it you know AI or enemy or something and so then when you're setting up your collisions you can you can pick what you want to do depending on the tags I'll show you how to do that right now so let's select the mail a box here and let's scroll all the way down on component begin overlap this is what we want here so now this is gonna drive the the mail a box here and one more thing we want to make sure mainly about the mail a box make sure the collision is set to no collision because what we're gonna do is we're gonna enable the collision or a split second during the actual attack animation so I'll show you guys how to do that as well but for now let's just do this here so off of this other actor if you type in tag it'll get this actor has tag so this is where you can actually check for the the actor that you're overlapping so in our case I'm gonna type in what did I have for the tag by the way it's player so we want to do stuff if we hit a player now if we have enemies like if you have a I then maybe you'll do another actor has tag and you'll have like a I or enemy or something like that but in our case we just have another player so we're gonna pretend this is like a 1v1 arena game or something I don't know but anyway we only want to continue if whoever we're overlapping with this box this box right here we only want to do functionality if it's a player that's it that's all that this is doing we're just checking that so from here we would now do you know damage or whatever so let's set that up right here we can come down here and just type them an event any damage and then from here we might actually you know what will make a variable right here called health we'll make the health a float and we will compile it and save it and we'll set the health to a hundred and what we do here now as we go health - so let me do that slow okay health just type in - twice you get double - and then just do float - float so it's the 100 - the damage coming in then we actually set this to the new health like this okay so where does this event get called from well it can get called from right here we can do apply damage and we plug in other actor here say we do a base damage of like 22 set damage class - damage type and then damage caused er it's looking for an actor so we can just get a reference to self and plug that in okay and then what we want to do here is we want to go if health is less than or equal to zero we want to like kill the player for example okay so I think what I'll do here is I'll do like a play chin you know this is very simple you wouldn't actually do this but I don't want to like get into a whole death like a whole death thing as well but if we have time we'll do it we probably won't have time okay I'm gonna grab just a simple death animation here death there it is okay I plug that in there we do not want it looping and we also want to get rid of this animation asset here we want to do mesh set in mode to use animation asset like this hopefully that'll work it might not but it's whatever it's this video is about a combat system so the question is how do we actually register this damage here because by default this mail a box the collision is not enabled we have it turned off and that's because we only want to enable when we're actually swinging the weapon and the answer to that is through a an animation montage here now they have three montages here so we would have to open up each one what I like to do is I actually like to put all the attacks into one animation montage but again I don't want to spend too much time on stuff like that I want to keep this tutorial as short as possible just to give you a nice little simple melee system to set up in your games that works so I'm going to open up a here and what I want to do is I need to make an animation notify state so what we do is I'm just gonna create one up here at the top you go blue loop print the class new blueprint class and then down here you can expand this type in and them notify and then right here and them notify state I'm gonna call it ans underscore melee for some reason it didn't spell Mele it just to M okay there it is let's open it up okay so here you have absolutely nothing right so what this animation notifies state is if you come into that montage here you have notifies right here if you right-click on the track you can add a notify state so now I can add our Mele right here but we actually don't have anything to do with it this is the beginning and this is the end but if you go in here we're not doing anything in the beginning or the end so what you have to do is in the top left in the functions here you click override you can override the beginning and the end so I'm going to override the beginning and I'm going to override the end and I'm actually going to override the name as well because if you look it just says ans in melee we can actually override that and rename this to like you know melee attack compile save and then now it's if I close this montage and reopen it now says melee attack okay and what we want to do is is we want to position it oops we want to position this so it's out of location right when the attack starts like right right about here I would say about here we would open up the collision so we put this at the beginning and then at work ends like right here we would close the collision we would disable it and so we have put the end there so right here we enable collision right here we disable okay so I'm going to save that and then now we need to set the functionality so the question is what do we do in the beginning now well oh this is the end let me go the begin okay so we're at the notify began we're overriding the begin so what do we want to do here at the very beginning what are we trying to do we're trying to we're trying to enable this collision box okay this box we're trying to enable collision because right now it's disabled we want to set it to query only for like a split second and then set it back to no collision right here so we enable it here and then we disable it here enable disable okay so what we want to do is under this mesh component we can actually get the owner you can actually cast to the Greystone player-character like this and then from here we can get the la box like this I'm actually going to right-click and convert to a peer cast here and now with this melee box we can set collision enabled and we can set it to now query only so now in the beginning when it hits this and hits this beginning part box is now enabled okay and then right here it's going to be disabled so we need to set the disabled up now so now we're going to go into the end and we're going to do the same thing so we go get owner not one er get owner cast to Greystone player-character and then get mail a box I don't know why it just doesn't come down here and then set vision enabled and we want it we we do want it to be no collision you want to disable the collision at the end so it's only enabled for like a split second okay so now we need to test if this actually works well the problem is that we is we have three montages in this character so we got to go set that up for B and C so I'm just gonna browse to it we're gonna add the notify state ans melee and so let's find out the beginning you want to open the collision right here or enable the collision right there and then well actually probably a little bit more back a little bit just in case so right here and then close it right there or disable it oh great before yeah like that that's good maybe a little bit more right there okay so that's B now let's do C added up by state ANS melee okay let's see right enable it here close it right there okay now to make sure this works what I'm just gonna do a print string here we'll print out the damage okay I'm damaging myself so that is actually something we have to fix really quick so what we have to do here is off of other actor we have to go does not equal the reference to self and then will we plug that in we don't want to be damaging ourself here because our self our own player also has a tag of player so we're actually damaging ourself when we do this so we just want to make sure that we're not damaging ourselves only damage other Graystone's silly okay not damaging ourself anymore I disabled okay for some reason I deleted this print string I promise I'm not on drugs okay let's see okay so see we do 22 see in the left corner see if you'll play the death animation it does yay okay so if you can see I'm running into a an invisible collision what that is is that this capsule component I'm running into it so when the player dies right here we want to set collision enabled to know collision let's try it one more time Oh 22 22 22 22 die he's dead I'm now running through him and there you go so guys that is it just a really straightforward simple melee combat system that will work for multiplayer you would have to do a little bit more work and the death stuff if you're doing multiplayer because damage is ran on server this is all run on server and just to make sure just to show you a little multiplayer setup here you would have a switch has authority right here just to make sure that the collision is only happening on the server but if I play this as a client you it just still be damaging nope it's not and I think that's because I have to I would have to turn a bunch of this stuff here into multiplayer logic as well but I'm not gonna do that because it would Jason it would just take a little bit a little bit too much time for that but we can do that in another video if you guys really want to see a continuation of this tutorial and you would like me to set this up for a multiplayer system let me just comment below let me know and if you made it this far do hit that thumbs up button guys it really supports the channel helps me out a lot and if you like the content and you want to come back for more just hit that subscribe button I do tutorials gaming videos dev vlogs you know we're just I'm just trying to make a really fun channel here where we can all hang out and have a good time so anyway guys I hope this video helps you with your games and I hope to see you around take care
Info
Channel: DevAddict
Views: 79,203
Rating: undefined out of 5
Keywords: UE4, UE4 Paragon, UE4 tutorial, UE4 melee combat, UE4 melee combat tutorial, tutorial UE4, Paragon, paragon tutorial, combat tutorial, Paragon combat, unreal engine 4, Unreal Engine 4 tutorial, melee combat tutorial ue4, devaddict, unreal engine melee combat tutorial, how to do melee combat in unreal engine, melee combat system ue4, melee hit detection
Id: JNUik-YLWUc
Channel Id: undefined
Length: 17min 59sec (1079 seconds)
Published: Thu Jun 25 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.