Welcome back everyone in the last video we finished up making this mando calculate damage macro inside of our BP enemy character base. In this video Our goal is to create the script to receive damage from an outside source from an outside source like a fireball or electro Spark, as well as create some script to damage our player if the enemy touches us so that we can actually see our HUD health working properly, let's deal with applying damage to our enemy when we hit them with a fireball or electro Spark. So I am going to jump over to our Event Graph inside of our BP enemy character base. And if you pause between videos here, this is the directory on how to find your BP enemy character bass. Double click on her to open her up in any Event Graph I already have my calculate damage macker out here which you can get by left clicking over here dragging and dropping it into your graph.
And directly to the left of this I'm going to right click and bring in an event called any damage this guy so in the last video, we looked at our BP fireball in our BP electro Spark, and each of these blueprints, had a function node called a ply damage in which we are plugging in a damage value and a damage type that's in our BP electro Spark. This is in our BP fireball in all this information is coming from our fireball attributes and our electro spark attributes that were populated inside of our BP player. So as soon as this gets passed into this node, right apply damage. This is is actually going to tell this event any damage here inside of our enemy base character to fire out we're going to take our execution pin plug it in here how much damage did we do well that is going to be supplied by this information right here the base damage and what type of damage did they do?
Well again here in our fireball, we plugged in a damage type into our damage type class. So let's just pass that along as well damage type incoming damage type. All right now and based upon all the math that is taking place inside of our calculate damage macro here which you can actually see by just double clicking on it. Remember this awesome script. Now we can have different effects happen based on the result of that math and if our character was vulnerable or resistant to that damage type So this is how we're going to do this, I am going to bring in a reference to our mesh. Our mesh has its transform set right down there at the character's feet.
I'm going to bring in a reference to our mesh and I'm going to drag off of this and say get the world location of that mesh basically right at our character's feet there. And the reason I want to do that is because off of this return value, I'm going to say spawn emitter at location. I'm going to bring in one of these and slop the emitter as p underscore flame explode. This is in the Infinity Blade effects pack By the way, you can slot in whatever makes you happy. And then I'm going to copy this node by hitting Ctrl C and Ctrl V to paste and I'm going to plug in this get world location into this spawn emitter at location. Okay, and what I'm going to do is I'm going to say if our character is vulnerable to a given damage type, which currently we've got set to fire, we're going to spawn this flame explode, only, I am going to make the scale here two times is big in the x, y and z.
So it's going to be a more grand explosion if it actually kills them. However, if they're vulnerable to that damage type, but it does not kill them, it only damages them. I'm going to plug into this emitter, which I'm going to say play that flame explode. Let's just keep the scale at one. And I'm saying to spawn this at our meshes world location basically at our feet here, just because that's where the particle effect is going to look most natural. And I discovered that through testing.
Okay, so with this done, I'm gonna move this up a little bit. We'll see this come into play in just a little bit. Now I'm going to highlight these nodes right here, left click and drag, I'm going to hit Ctrl C, and then I'm going to hit Ctrl V down here to kind of paste in a nother series only for if our character resists that given damage type. I'm going to plug into these two. Well, I don't want to do the flame explode for if they resist this damage type. Remember, our enemy character here is going to resist some lightning damage.
So I'm going to set our emitter here to be there's one called line to point underscore, blast, underscore, lightning. That one right there, line two point blast lightning 00. And this also is in the Infinity Blade effects pack. And again, you can use whichever one you want. So I'm gonna slay a slot that in there is Well is line two point underscore blast underscore lightening slotting that into both of these for our resistance the top most one if it's going to kill our player they're said they're resistant to damage type but they're still gonna kill them. I'm gonna make the scale be 1.5 1.5 and 1.5.
However if they are resistant to that damage type and it does not kill them, I'm going to change the scale here to be point seven, five in the x, the y and the Z. Okay, so we've got different particle effects that are gonna play depending on if they're vulnerable or resistant to them. Now I'm going to select these nodes again. Ctrl C Ctrl V and paste another copy down here for if we calculate damage and our character is neither resistant nor vulnerable, so I'm going to set normal death into here. Normal damage into here only. I don't want to play this at the location of our mesh.
For this one I'm going to play at the location of our capsule component. What am I going to play and our capsule components location, and let me just jump to the viewport our capsule component has the transform basically right in the middle. So imagine this particle effect that we're about spawn gonna be playing right in the middle there. For this one, we're just gonna do a regular explosion good old p explosion. p underscore explosion p underscore explosion and if it kills them, I'm gonna set the scale here to be either flip my page and notes I'll set it to be twos across the board. Two, two and two.
And if it doesn't kill him, I'm going to set the scale to the one, one and one now. Note that it actually kills the character. Whether it be the vulnerable death The resistant death or the normal death, I need to bring in a destroy actor node. So it's gonna, this one is going to destroy gonna hit Ctrl C. resistent death This one is going to destroy so essentially every other one here and then normal death. This one is going to destroy as well. Okay.
So let me left click and drag around all these notes. Hit the C key and I'm gonna say Apply. Let me zoom up a little bit apply damage to enemy. All right, let's quickly Compile and Save and we should be able to test this out. So just clicking on play over here. Okay, our character is not fireball so let me shoot out a fireball and in the upper left hand corner of my viewport you should see how much damage our enemy has been output to the screen as well.
So here we go fireball against our enemy character which they are vulnerable against. Boom, you can see a big old explosion you saw 0.0 up there in the left hand corner of the screen. Let's do a few things here. Let's go into our MV test map. Let me select my enemy character. I'm going to go all the way down to my default settings so I can modify some of this to do where was it, okay, so I'm going to change my vulnerable multiplier here to be Simply 1.5 so that's not going to be enough damage to kill them.
Fireballs do 50 damage times 1.5 should 1.5 should now be 75 damage. So now watch what happens when I jump in and play. The explosion should be a little bit smaller and it should not destroy our character the first time a little bit smaller and you see 25 health, this next one should kill them and that effect should be bigger. Okay, so we saw that play let me select my enemy character once again here. We're gonna set this back to zero. How about I change the given spell that I'm casting to my lightning.
Okay, let's try lightning next. Let me just click play here. So I am in the editor, I'm just going to hit Shift plus f1. That's going to give me control of my mouse. And now if I select my BP player that has now appeared in my world outliner I'm going to come under I'm going to come under my player info my be magic slotted which I've made available here in the editor this be magic slotted variable here in my BP player. Now remember, I made this be magic slotted variable, I clicked that eyeball icon so that I could edit it in.
In the editor over here, I'm going to change this over to be electrical Spark. So now let me bring on my window once again. And now we got to click on my window to give myself access to it again. Now when I hit the one key, I should be doing electrical Spark. Look at the damage value that's gonna be up output in the upper left hand corner of the screen as well as the particle effect that's going to play when it hits my character. Okay, so 50 damage.
Okay, let me do it. Once again. Missed on that one. Let me get a little bit closer and actually I can't catch it anymore cuz I'm out of mana so let me jump out of here jump back in and play I'm still doing fireballs I gotta go back to let me jump in and play shift plus f1 gonna grab my player and I'm gonna say hey do you lecture spark alright so one to damage them with the lecture spark effect and then one again this one should killer effect was just a little bit bigger so you have now created a damage script for your enemy pretty sweet and you've seen how you can select your enemy character here and you can swap out all kinds of things about your enemy straight away from the Details panel with those exposed variables. You can change things like what is their damaged vulnerable class, their damage resist class you can even modify that multipliers and their health values.
That is all well and good. Now how about we move on to creating a little bit of script where our enemy can actually damage us, this should be relatively simple to do. So let's just jump back into our BP enemy character base. I am going to add a brand new variable over here and I'm going to call it attack damage. This is how much damage that our enemies going to deal to us. I'm going to compile here and save.
And sure I'll make this instance editable as well and I'll say they're gonna deal 25 damage to us. Now with that done, I need to find a new spot here in my Event Graph away from our apply damage. Let's just go over to the right here a little bit. And I am going to right click and bring in an event. Hit So often the event hit I'm going to drag out of the other actor in find out cast to BP player. If the thing that hit us the enemy character was the BP player.
If it was, I'm going to drag out of this as BP player. I'm going to type in apply damage this function right here. And I'm going to create some space between the two. I'm gonna double click on this wire here once in twice to bring in a reroute node because I'm going to put something in between here What am I going to put in between here I'm going to drag out of my BP player and bring in a do one snowed. Why do two one snow because when our BP player bumped in to our enemy character, I only want to apply that damage one time and not have it repeat itself quickly. So I'm gonna say do it once apply that damage and then off of the apply damage.
I'm gonna drag out a one Bring in a delay node and we're gonna make this delay for let me just snug these up a little bit closer like that. I'm gonna bring in a delay a half a second 0.5 seconds and I'm gonna say after half second delay if BP player you bump into the enemy character, we're gonna say you can get damaged once again. Okay, so you saw how that we're just resetting that do once known so it can happen again. Now how much damage do we want to deal well, let's plug in our Attack Damage variable here which says 25 damage. Okay, so we've got this applied damage going on here inside of our BP enemy character base. Let's quickly Compile and Save.
But our BP player right now does not have an event to receive any damage and do something with that. So let's fix that. Let's go back to our BPP key player quickly in content, Metroidvania, blueprints characters BP player. Let's jump over to the Event Graph tab here we've got some test scripts where we were updating our health by just tapping the H key just showed that our health meter would actually work. And right below my test scripts, I'm going to right click, and I'm going to type in event, any damage so if we receive any damage, like we're doing over here in our BP enemy character, we're saying the damage actor is our BP player, we want to apply damage to the BP player. We're going to drag out of here and simply say, update health.
Here is my update health function that I've created inside of my BP player, I simply could have gotten it by dragging and dropping into the graph is well, how much damage should be applied. Well, we're going to pass that on into our incoming damage of our update health node. And again, that is determined by the damage in my BP enemy character that we're specifying right here that we're feeding into this applied damage function. So with our BP player, now having this little bit of script I can compile in save. Let me just left click drag around this tap Escape key and say player receives damage. Let me compile and save one more time.
Now I should be able to jump in and play and when I run my character into the enemy, watch my health in the upper left hand portion of my HUD. We go down to 75. We go down to 50. We go down to 25 and we go down to zero now we're not actually doing anything when our health is down to zero, but we could Alright guys, that is Going to Do it all for this series of videos now we've got an enemy character that we can damage with our fireball and our electro spark and we've made it so that our enemy character can damage us if we run into it. That'll do it all for this one. We'll see you guys in the next one.