Welcome back.
So we almost have the behavior we want.
Our shaman summons some minions, and after that it launches fireballs.
We want to summon more minions when we get below a certain threshold.
In other words, if I kill four of these five enemies, then I want our minion to summon more.
And that means our minion needs to know when an enemy has been killed.
It needs to know when that enemy has died.
Now an easy way is to go into our summon ability, and right after we spawn an actor, we take that
actor and we type in on Destroyed and there's a delegate broadcast whenever something is destroyed.
Now, yes, there's a delay of a few seconds.
So once our enemy is killed, then there will be a delay of lifespan, which is a member variable we
added to our character class after that delay, then the enemy will actually be destroyed, at which
point it's on destroyed delegate will be broadcast.
So this is something that works, if we don't mind that little bit of delay.
So let's click Assign on Destroy.
That's going to create a on destroyed event automatically.
And when one of these minions is destroyed, we can use increment minion count passing in a negative
one and we can hook that up.
But this has to be our avatar actor.
So we'll get that and pass that in for the target and this bind has to be reached.
So we're going to bind shortly after spawning.
So we'll put this bind right here.
Like so.
And then once we destroy an enemy that will result in decrementing our minion count.
So let's test this out.
I'm going to press play.
There's our five minions.
Let's make sure that we don't die in the process of testing this.
I'm going to kill these.
And as soon as we get down to one, within five seconds, we should see.
Our shaman summoned more.
All right, so we're down to one.
Our shaman is not summoning.
Yes, our shaman summoned more.
There was that delay, remember?
So we have that delay.
But now we get the behavior we want.
Our shaman will summon more if it's down to one minion left.
Otherwise it's going to sit there launching fireballs.
Now, another thing I'm noticing is my ranged.
Demons are not throwing rocks, are they?
And that tells me that I must not have their class, their character class set to elementalist.
Let's see if we just get one more.
Some in here.
There, we got it.
Okay, So I'm going to make sure that our ranged demons can do their range attacks real quick.
So I'm going to go to Character Demon, Open Demon Ranger and search for character class.
Yes, it's set to Warrior.
We need to set this to Ranger.
And now if we just really quickly test that.
Now we see that they're launching their rocks.
Looks like the rocks are colliding probably with the ground.
It looks like the same issue that our shaman had.
So we're going to go ahead and fix that.
It looks like they're throwing the slingshot rock, right?
So let's go to Blueprints Ability System Enemy.
Abilities.
BP Slingshot Rock.
Their overlap sphere and we'll just use the same solution that we used in the Aura projectile.
I don't really feel like making a base blueprint they can both derive from just to get this same behavior.
All I want to do is in begin play, disable that sphere collision.
So set collision enabled.
We'll set it to no collision.
We'll do a 0.1 second delay.
0.1 seconds.
And after that delay, we'll set collision enabled.
And we'll set it to.
Query only.
In fact, we don't need to set collision enabled first.
We can just do what we did in the fireball.
We can just set this to no collision, No need to set it to no collision.
We'll just have a delay and set it to query only after 0.1 seconds.
Let's see if that helps.
That's better.
Although I do see that it's kind of throwing the rock downward.
So for that reason, I'm just going to check out that ranged attack.
Gar ranged attack.
And let's just take a look at the projectile target location and see what that is.
I'm going to draw a debug sphere for it.
And that's going to be that combat target location that we're passing in to spawn projectile.
And I'll give it a duration of three seconds, a radius of 12.
And a line color of magenta.
Let's see what that is, if we can see it.
Okay, so it is.
Looking correct.
It's at our combat target location for them, which is aura.
So for some reason, the Slingshot rock looks like it's colliding probably with the ground, which means
that that sphere may have to be a bit smaller for the rock.
Let's see if that fixes it.
I think that does.
Yep, that fixes it.
And I think we will want to angle that rock upward and we'll do that.
As well.
I think what we can do is our ranged attack is calling spawn projectile, spawn projectile could have
a pitch override and we can put some kind of a little bit of a pitch elevation of sorts for spawn projectile.
And that way when we spawn one with or a projectile spell, then we can spawn it sort of at an upward
pitch.
So here in aura projectile spell, spawn projectile, we're setting the rotation here.
The rotation is the vector from socket location to projectile target location, convert it to a rotator.
What we can do is override that pitch, but only if we want to.
So I'm going to make a parameter that can go into spawn projectile for overriding the pitch and a boolean
for whether or not we want to do that.
So Spawn Projectile can now take a bool called be override pitch.
We'll set it equal to false by default.
So if we don't pass anything in, nothing will happen.
And then we'll have a float called pitch override and we'll set this to zero by default.
And that way nothing will happen if we don't pass that one in.
And then we'll add this to the CP file right here.
We don't need to set those default values here just in the H file and we'll check if we should override
the pitch.
So for the rotation here, we'll say if be override pitch and if we do, we'll take our spawn transform's
rotation and change it.
In fact, we'll just change the rotation before setting the spawn transform rotation.
So we'll do this right here just after setting the rotation.
If be override pitch, then we'll take rotation, dot pitch and set it equal to pitch override.
That way we can give a little bit of a pitch override.
So let's go ahead and we'll close the editor.
And we'll compile and launch again and set a pitch override for that ranged attack.
This is going to affect our slingshot enemies as well.
So something to keep in mind.
Okay.
So back here in ranged attack, if I check override pitch and I give this a value, say 35, then we
should see those rocks thrown at a 35 degree pitch.
Let's see if that works.
There we go.
Look at that.
They're flying much farther because they're really launching those things.
And that's going to also affect our slingshot enemies, by the way, as I mentioned.
So that could be something we wish to parameterize.
We could also make a ranged attack specific to the character.
We could have a parameter on the character and an interface function to get it.
There are numerous options, but I want to see just really quickly how this affects our slingshot enemy
and we may find a value that works for both of them.
So I'm going to go to Goblin Slingshot, drag in a goblin slingshot and press play.
And of course, my goblin slingshot is behaving like a melee attacker.
And that's because if I right click on it and edit Goblin, Slingshot and search for character class.
Sure enough, it's set to Warrior.
I want it set to Ranger.
Now it'll act like a ranger.
There we go.
So it's a little bit high.
I think it's a little high for the rock to actually it looks good for the rock.
And I think.
Our enemies pitch.
For the slingshot is a little high.
Now, realistically, you could calculate the distance between them and calculate the correct pitch
that would give you an accurate shot.
And that would be a bit of a kind of physics problem to solve, which would be pretty fun.
I'm not going to go that deep.
I'm just going to take my range attack and set the pitch override to 25 and call it done.
But take it as an optional challenge.
If you'd like to calculate the pitch dynamically based on distance.
But I think this is good.
This gives you a bit of a distance that will be considered dangerous for you that you can try to avoid.
Perfect.
And of course, if we eliminate some of these demons, if we don't die in the process.
Well, then we'll get more demons spawned.
But it looks like I died, so.
Okay, well, we did what we set out to do.
We now have a minion count.
And as long as that minion count gets down to below the minion count threshold, we get more minions.
And I'm just going to really quickly test that.
This is a little bit harder with all rock throwing enemies, but we're going to manage and once we get
more powerful abilities, then we won't be so overwhelmed.
Okay, we're down to one and let's see if we can get that summon ability.
There it is.
We have the summon ability.
Perfect.
Excellent job.
In the next video, we'll work on summoning those minions in a more attractive manner rather than just
popping in.
We'll be adding some juice to our game.
Excellent.
I'll see you in the next video.