All right.
Now we're going to actually add some code
to our sword attack.
Okay.
So currently it's pretty barebones.
It just gets thrown into the wild without any code inside it.
But now let's give it some code.
So for starters, we are going to create an AI component
when hit with the paper Sprite right now.
First things first.
The hit we want to record
is cost to Melee Enemy.
Okay.
So this is going to happen when it hits the melee enemy.
That's very, very important.
And when it comes to other actor, it's basically the melee enemy.
So the other actor is the object that it hits.
That's important.
And then it's going to apply damage.
How much damage?
I think three hit kills for enemies is good.
So let's say 30 damage.
I think 30 damage is good.
So that's three hits.
Technically. Four hits.
Okay, fine.
Let's make it.
No, let's make it. Let's see.
What would it take to get three hits?
Let's say that is seven damage.
Okay, so let's do some basic math.
Okay.
So if we make it so that it does
30 damage, 30 times 390.
Okay.
If we make it do 37 damage times three and perfect
47 damage, it is, That's enough to kill the enemy.
That's great.
Now, once it's done
applying this damage, I wanted to destroy itself.
We can't have random sticks and swords sticking around.
So destroy
actor.
And I wanted to destroy this self.
Okay, So immediately it has done any damage.
I want it to be out of there.
Now he has the thing
we need it to still destroy
itself, even if it does
nothing.
Okay, so what?
I guess Let me show you what this looks like in action.
And. Okay, so come on over here.
Okay, We'll spawn one or snap out looking the other way.
Okay. Boom!
It gets eaten up.
Okay. Boom! It gets.
It does damage. Okay?
It is actually doing damage.
It's just. It.
It attacks.
Okay. It's doing damage. Okay?
The attacks are doing damage. And it's.
yeah, the enemy has lost track of me.
I snapped through.
I snapped about killed.
Okay, so right now, the sword attack does disappear after doing damage.
But we want it to disappear regardless.
So we'll create an event tech,
and we're going to create a basic delay.
Now, this delay, here is the delay.
In other words, it's how long the attack exists.
So I'm just going to set this up to 0.1.
And once that's completed,
destroy itself basically from the moment it's created,
it's only on screen for 0.1 seconds.
Let's see how that looks in game.
So it's okay.
It's on for just 0.1 seconds.
Snap. I run into this.
Okay, So let's come over here.
Okay.
Something helpful.
Okay.
A snap.
I'm basically being eaten alive.
snap.
Damn.
But that's perfectly fine. Okay.
So right now, our enemy saw it.
Our little sort of idea is able to completely demolish this.
It can't hurt because it has no damage, but it shows up for a brief flash.
That's why it's basically a little spawn for 0.1 seconds.
Then it's gone.
This is good because it's this one that doesn't stay on forever with magic.
So let that damage over time.
Now we're going to give the melee enemy
acceptance
of the damage that's coming its way.
So let's go into the melee enemy.
Speaking of which, at some point
I'm going to make a video of us cleaning up this code anyway.
We'll go up in the melee enemy
and we'll create a simple event.
Any damage or in other words, any damage
that it's being told that it is receiving?
Okay. We will get.
And then me health.
Okay.
So basically get enemy help,
get the damage and we're going to subtract.
Yeah. Okay.
So enemy health is what's at the top here.
It's what's being subtracted.
We're going to subtract by the damage that gets done.
Okay.
Very important.
Less obstructing the damage that gets done.
And then we're going to set it to
enemy health, right.
So that whatever it takes is going to be the new enemy health now.
Okay.
Whenever it comes to this number over here,
we are going to do a less than equal to.
Okay.
So it's less
the moment it's health reaches zero,
then we want it to branch.
So create another branch.
So the moment it's health reaches zero.
You know what?
Not this animations.
I want it to destroy
the actor.
Okay.
That's all it has to do immediately.
The health bar of the melee enemy.
It's zero.
It gets destroyed.
Now, let's go.
Okay, it's coming.
I'm not ready to fight.
Snap.
Need to jump.
Okay.
snap.
Okay. I died.
I die like a noob.
An absolute noob.
Let's go back and try and rebalance this a bit.
Okay, So for starters, I think that that delay attack cooldown.
Let me bring it down from 1 to 0.5.
Okay.
Then the sword attack its duration.
Let me increase it from 1 to 0.5.
Okay.
So I'm able to always sword attack.
This isn't like proper balance for real game, but it's for demonstration.
The balance.
I leave it to you.
So let's play again.
Go in for another fight.
It's not about looking backwards.
Look back at the enemy. Snap
or snap. Attack is incorrect.
Okay,
sweet.
Okay, cool.
It should be three, then it dies.
What the hell?
Where is the mistake?
There is a mistake in our code.
my goodness.
If this is less than or equal to zero, then true.
Destroy the actor.
The actor is the self.
Okay, so
what I want to do, because this is not making sense.
Why is the enemy not dying?
The enemy should be dying.
Let's quickly run through this code again to just double check.
This is perfect.
This works.
What exactly is missing
should be easy in the sword attack.
Double check the sword attack again.
So currently the sword attack on hit right?
When it hits the melee enemy,
it applies 37 damage It did.
Then it destroys itself.
That's cool.
Every event tick
there is a delay of 0.5.
Once that's done, it destroys itself.
Okay, that's fine.
But I think what I want,
I think what I want
is a way to truly understand
when the base damage is doing this proper damage.
Let's look at the player. Okay?
The player is entirely doing its job.
There's nothing wrong there.
So let's go into the melee enemy.
Let's see
when any damage,
let's do a simple print
to do some debugging and we'll see
that enemy hit.
So that just shows that at least the on any damage is walking.
Okay, so enemy is hit.
Is hit.
Okay, perfect.
Okay, let's have another look.
You come over here.
Come on. Come to me up
in the knee.
okay.
That is on cooldown.
Hold on.
Going to wait
was not.
I'm actually not hitting the enemy.
No shit.
Hold up.
Wait a minute.
It's. Come back here.
Come back to the melee enemy.
I'm going to stop the melee and then me from moving on different axes.
Okay, so let's start by constraining it.
It's been okay.
Just.
I'm not.
I don't need its rotation to be changed.
Just its position in the Y-axis.
Okay, let's try this again.
So if I come over here.
Okay.
snap.
Holy snap,
Holy snap.
We have a we have an enemy that's moving too fast.
We have an enemy that's moving way too fast.
So fast Things fast
moving change.
It's speed.
Okay, Walk, speed. 400.
Now let's bring that down to 300.
That's getting crazy.
Okay, first things first.
Warp speed, 302nd.
We know that the on event in the damage
is not correctly applying damage.
Right?
So quick check
event and the damage it needs to say enemies hit.
Let's remove any athletics
whereby it's seeing enemies attacking the enemy attack with no walks.
We don't need that anymore.
So we know currently
we only have text on enemies hit.
So let's try that again with a slightly slower enemy.
If this doesn't work, it's going to be more troubleshooting.
Let's see.
snap,
run, attack isn't on cooldown.
my goodness.
my goodness. This.
For some reason, this character is moving around a lot.
Let me quickly
find a fix and come back again.