Unreal Engine 5.1 - AI Melee Attack/Damage Player - FPS Part 31

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone today we're going to see how to get some damage done with our AI so the AI is going to attack me is doing a sphere and I lose Elton on the left left corner and if I keep going that way I'm gonna die but if I move out of the sphere so I don't receive any damage so let's the AI kill us so we can have our death widget appear on the screen and we can just restart the game so we're gonna see how to have our AI do damage to the player well the first step is going to go to our animation so just go to your animation folder select the attack animation that you have and here we're gonna do a notify so you can see here you can move by clicking on where you want the Notifier to start so around here I'm gonna make a notify that we're gonna click right here after notify there was one here so we're gonna go there and just right click and you can do a notify I'm going to do a montage notify and now we can click on that modify and change the name for it so we're going to do attack so when the animation reach this location it's gonna pull this notify that we are going to use to do some damage so we're going to save that go back to our NPC master and here after the even melee attack we're playing a montage so it's exactly that Montage which is referred to the animation here that we're going to use to do damage to our player so the first thing when this montage is playing we're gonna play a sound and you can do a sound 2D or at location it's up to you I'm going to take a 2d for this example and there's a different sound obviously that we can use in the game so I'm going to take this one for an example there we go I'm gonna click this and I'm just gonna remove 0.5 on it so it's going to be less loud in the game and that sounds gonna play each time that our AI attacks so basically here you put the sound that you want your AI to do when the AI attack so on the unnotify begin here it's where we're gonna use fear overlap actor so we can do damage but before using that we have to use a sphere Collision so if we go back to our viewport here had a sphere here I'm just going to remove it to show you exactly how to do this so we're clicking on the components we're gonna click add and we're going to search for sphere and I'm going to take the sphere Collision so this one here now you can see here the sphere is there we're going to make sure that we attach that under the mesh and here if we click on the sphere we have a parent socket in the detail panel so we can just click here on the browse icon and basically we're going to search for n and I'm going to take the end that we want so our animation play on the right and so we're going to select write in now you can see that the animation is attached to sphere however it's not at the good location so you could drag that manually to the hand or here under the transform in the detail panel you can click here and just reset the value to zero so if I click there it's going to reset to zero zero zero which is going to put the sphere Collision right in the end of our AI so now we can compile and we're all good for the sphere so we're going to go back to the event graph here in the event graph it's where we're going to do all logic to have our player receive damage so on the notify begin we're going to drag from that and we're going to search for a sphere and it's going to be an overlap sphere that we have to select so the overlap sphere here so we're going to take the actor here so from the sphere overlap actor we have to do not to do but we have to determine where we want or sphere to appear well it's it's simple so we're going to get the location so get the roll location so get roll location of the mesh but for the sphere so the sphere Collision that we want so we're going to take this one here and now it's going to put automatically that sphere right here in the target so it's exactly what we want so now the sphere is going to appear at the row location where it's supposed to go so from the object type we're going to derive from that and we're just gonna not promote that to a variable but we're going to make an array and in that array we're going to make sure that the object type is a pound and the actor class well is going to be our first player character or the name of your character for yourself and the in your actor well we don't want to do damage to our AI so we don't want the AI to kill himself so what we're going to do we're going to drive from the actor and we're going to also make an array because we cannot connect right away self to it because let's take an input for an array so we'll create an array first and after this we can select reference to self so every time the AI attack will not receive damage which is important so the sphere radius is how big we want or sphere to be in the game so I'm going to select uh maybe 50 I think 50 would be good however um I'm just going to drag from that in primal distributable and I'm just gonna call that attack sphere ranges so that way depend of the character that we use when we do child blueprint later on for different enemy we can easily change that sphere radius okay whoops we're gonna go back here so we can change that on the fly so it's going to be easier instead of coming in the parent class to change that so we're going to leave that as here however after compiling in the detail panel we need to make sure that we put a number by default so I'm going to put 25 by default so each actor that's going to use the NPC master class will have this value as 25 by default so I'm gonna put that under the category combat so I'm gonna put that under combat so from the sphere overlap what we're gonna do we're gonna drag from that and we're gonna search for debugs here you don't have to put that but however if you want to see your sphere when our AI attack you will need that however we're gonna make sure that we disactivate that when we play the game without I mean if we don't try to debug anything or see anything we need to make sure that we remove this so what I'm gonna do from that the center here because we want our sphere to appear on the screen we're going to connect that directly to our get location here I'm going to do a reroute node so it's look a little bit better and the radius of that sphere well we want to bring that sphere to be this one here so what we could do we could take basically this one and just plug it right there so every time we change this radius is going to automatically update this one at the same time so that's very convenient so from the color well I'm going to put a red because I like red and the duration well I want that sphere to last I don't know three seconds on the screen however I'm going to promote this to a variable and I'm gonna call that fear duration and same thing we have to compile first and here in the detail panel we're gonna have three now so each actor that's going to use this blueprint will be able to change that as well so we have that here I'm gonna put that under category and I'm going to change the category for debug there we go right there is under debug I'm going to make sure I put keyboard tools here we go so that way I can cancel that very easily by changing that so we're not gonna see that debug on the screen so from the debug sphere we are going to drag and we're going to search for for each Loop so each time that the code go through this it's going to do something so the array will be connected to the array here of or sphere overlap actor so for each Loop here every time the code go through that Loop well we want to apply damage we're going to apply damage we're going to take the first one so it's going to apply damage to our player so well we're going to connect our damage actor to the error element right here the base damage that we want or AI to do well you can put a number here or you can just drag and promote this to a variable and I'm gonna call that Attack Base damage and I'm gonna put that under or combat category I'm gonna compile Now by default the attack gonna be zero so I want to be 25 by default so we can test it out the investigator will be the controller itself of this AI so I'm gonna cry drag from the event investigator and we're gonna get our controller so we get controller I'm going to get the pound controller and the Damage closer will be self so who is doing the damage is going to be Rai so self and the damage type I'm going to select the damage tag by default here I guess we're done here I think we can do a try run and see if it's worked for us so we're gonna go through the code just make sure that everything is done probably so when the even melee attack is done it's going to play a montage which is going to play a sound for us and the notify that we set up on our animation right here will trigger at this specific location when the animation is playing which gonna trigger this pin here which is going to create that sphere that overlap an actor if it's overlap or actor or player it's going to do damage so that's where we're gonna spam at the row location of our actor it's going to do we are setting the attack sphere radio so we set up that it's going to be 25 so it's going to be 25 a radius item it's going to be a circle of 25 I think unit or something like this so we can play with that number if we think it's too small and from that we're going to move it's going to draw or debugs fair so we can visually see what's happening on the screen and each time it's going to go through that code it's going to apply damage to our player so let's try it out so we're going to do play and we have our AI here it's running at us it's attacking so you can see the sphere Collision here and you can hear the little sound at Play however you can see that it's attacking but it's not really touching us because we're not ready there so what we're going to do we're just gonna go back there and we're just going to increase the sphere radius Maybe by 50. so this way it's going to give a chance to the AI to hit us one like this here we go so now we are losing him if we move out it's not doing any damage to us and if we stay there we are going to die and we can obviously replay or quit the game so we can just click replay and we're back in the game so I will leave you on this guys and hopefully I will catch you on the next one so thank you for watching
Info
Channel: Unreal By Yourself
Views: 9,441
Rating: undefined out of 5
Keywords: Unreal Engine 5, Unreal By Yourself, Unreal Engine Beginner Tutorials, how to use unreal engine 5, how to learn unreal engine, creating video games, unreal engine series, Is unreal engine worth it, health, Sprint, Slow time, Widget, Enemy, Blueprint, Master Blueprint, Options menu, Settings, Shooting, Reloading, sounds, physical meterials, materials, Item pick up, Weapons, Aim down sight, Flashlight, flashlight, Recoil, Gamemode, gamemode, difficulty, Hard, series, Event Dispatcher
Id: Empzhuv0SQQ
Channel Id: undefined
Length: 12min 50sec (770 seconds)
Published: Fri Feb 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.