WEBVTT

00:06.810 --> 00:07.800
Welcome back.

00:07.800 --> 00:10.230
So we almost have the behavior we want.

00:10.260 --> 00:16.110
Our shaman summons some minions, and after that it launches fireballs.

00:16.110 --> 00:21.210
We want to summon more minions when we get below a certain threshold.

00:21.210 --> 00:27.990
In other words, if I kill four of these five enemies, then I want our minion to summon more.

00:28.080 --> 00:33.450
And that means our minion needs to know when an enemy has been killed.

00:33.450 --> 00:36.540
It needs to know when that enemy has died.

00:36.690 --> 00:42.990
Now an easy way is to go into our summon ability, and right after we spawn an actor, we take that

00:42.990 --> 00:52.380
actor and we type in on Destroyed and there's a delegate broadcast whenever something is destroyed.

00:52.410 --> 00:56.580
Now, yes, there's a delay of a few seconds.

00:56.580 --> 01:03.570
So once our enemy is killed, then there will be a delay of lifespan, which is a member variable we

01:03.570 --> 01:11.020
added to our character class after that delay, then the enemy will actually be destroyed, at which

01:11.020 --> 01:13.810
point it's on destroyed delegate will be broadcast.

01:13.810 --> 01:19.390
So this is something that works, if we don't mind that little bit of delay.

01:19.390 --> 01:21.760
So let's click Assign on Destroy.

01:21.760 --> 01:25.150
That's going to create a on destroyed event automatically.

01:25.150 --> 01:33.430
And when one of these minions is destroyed, we can use increment minion count passing in a negative

01:33.430 --> 01:36.370
one and we can hook that up.

01:36.370 --> 01:39.550
But this has to be our avatar actor.

01:40.050 --> 01:46.710
So we'll get that and pass that in for the target and this bind has to be reached.

01:46.920 --> 01:50.870
So we're going to bind shortly after spawning.

01:50.880 --> 01:53.070
So we'll put this bind right here.

01:54.280 --> 01:55.420
Like so.

01:56.060 --> 02:04.160
And then once we destroy an enemy that will result in decrementing our minion count.

02:04.190 --> 02:06.590
So let's test this out.

02:07.070 --> 02:08.420
I'm going to press play.

02:09.520 --> 02:11.310
There's our five minions.

02:11.320 --> 02:15.270
Let's make sure that we don't die in the process of testing this.

02:15.280 --> 02:17.380
I'm going to kill these.

02:17.380 --> 02:22.120
And as soon as we get down to one, within five seconds, we should see.

02:23.400 --> 02:25.170
Our shaman summoned more.

02:26.690 --> 02:29.120
All right, so we're down to one.

02:31.690 --> 02:33.040
Our shaman is not summoning.

02:33.040 --> 02:34.390
Yes, our shaman summoned more.

02:34.420 --> 02:36.090
There was that delay, remember?

02:36.100 --> 02:37.960
So we have that delay.

02:38.110 --> 02:41.290
But now we get the behavior we want.

02:41.290 --> 02:46.960
Our shaman will summon more if it's down to one minion left.

02:47.410 --> 02:50.650
Otherwise it's going to sit there launching fireballs.

02:50.680 --> 02:53.860
Now, another thing I'm noticing is my ranged.

02:53.860 --> 02:56.200
Demons are not throwing rocks, are they?

02:56.200 --> 03:03.040
And that tells me that I must not have their class, their character class set to elementalist.

03:03.810 --> 03:05.160
Let's see if we just get one more.

03:05.160 --> 03:06.130
Some in here.

03:06.150 --> 03:07.530
There, we got it.

03:07.740 --> 03:15.540
Okay, So I'm going to make sure that our ranged demons can do their range attacks real quick.

03:15.540 --> 03:22.680
So I'm going to go to Character Demon, Open Demon Ranger and search for character class.

03:24.970 --> 03:26.890
Yes, it's set to Warrior.

03:26.890 --> 03:29.590
We need to set this to Ranger.

03:30.540 --> 03:34.350
And now if we just really quickly test that.

03:34.380 --> 03:37.320
Now we see that they're launching their rocks.

03:37.350 --> 03:42.030
Looks like the rocks are colliding probably with the ground.

03:42.030 --> 03:45.600
It looks like the same issue that our shaman had.

03:45.600 --> 03:48.000
So we're going to go ahead and fix that.

03:48.420 --> 03:52.230
It looks like they're throwing the slingshot rock, right?

03:52.230 --> 03:56.610
So let's go to Blueprints Ability System Enemy.

03:57.540 --> 03:58.410
Abilities.

03:58.460 --> 04:00.300
BP Slingshot Rock.

04:00.840 --> 04:09.190
Their overlap sphere and we'll just use the same solution that we used in the Aura projectile.

04:09.210 --> 04:15.170
I don't really feel like making a base blueprint they can both derive from just to get this same behavior.

04:15.180 --> 04:20.340
All I want to do is in begin play, disable that sphere collision.

04:21.260 --> 04:23.690
So set collision enabled.

04:26.130 --> 04:27.570
We'll set it to no collision.

04:28.450 --> 04:31.300
We'll do a 0.1 second delay.

04:33.610 --> 04:34.870
0.1 seconds.

04:36.030 --> 04:40.260
And after that delay, we'll set collision enabled.

04:42.900 --> 04:44.610
And we'll set it to.

04:45.770 --> 04:46.880
Query only.

04:47.120 --> 04:49.640
In fact, we don't need to set collision enabled first.

04:49.640 --> 04:52.920
We can just do what we did in the fireball.

04:52.940 --> 04:57.440
We can just set this to no collision, No need to set it to no collision.

04:57.440 --> 05:02.030
We'll just have a delay and set it to query only after 0.1 seconds.

05:02.060 --> 05:03.710
Let's see if that helps.

05:07.270 --> 05:08.380
That's better.

05:08.800 --> 05:13.330
Although I do see that it's kind of throwing the rock downward.

05:15.220 --> 05:20.410
So for that reason, I'm just going to check out that ranged attack.

05:20.440 --> 05:22.170
Gar ranged attack.

05:22.180 --> 05:28.920
And let's just take a look at the projectile target location and see what that is.

05:28.930 --> 05:31.180
I'm going to draw a debug sphere for it.

05:34.650 --> 05:41.070
And that's going to be that combat target location that we're passing in to spawn projectile.

05:41.950 --> 05:48.040
And I'll give it a duration of three seconds, a radius of 12.

05:48.650 --> 05:50.840
And a line color of magenta.

05:51.660 --> 05:53.970
Let's see what that is, if we can see it.

06:01.780 --> 06:03.550
Okay, so it is.

06:04.500 --> 06:05.610
Looking correct.

06:05.610 --> 06:10.070
It's at our combat target location for them, which is aura.

06:14.730 --> 06:22.290
So for some reason, the Slingshot rock looks like it's colliding probably with the ground, which means

06:22.290 --> 06:26.910
that that sphere may have to be a bit smaller for the rock.

06:26.940 --> 06:28.560
Let's see if that fixes it.

06:32.350 --> 06:33.730
I think that does.

06:35.470 --> 06:36.760
Yep, that fixes it.

06:36.760 --> 06:41.980
And I think we will want to angle that rock upward and we'll do that.

06:42.650 --> 06:43.430
As well.

06:43.430 --> 06:50.510
I think what we can do is our ranged attack is calling spawn projectile, spawn projectile could have

06:50.510 --> 06:58.730
a pitch override and we can put some kind of a little bit of a pitch elevation of sorts for spawn projectile.

06:58.730 --> 07:06.110
And that way when we spawn one with or a projectile spell, then we can spawn it sort of at an upward

07:06.110 --> 07:06.790
pitch.

07:06.800 --> 07:13.730
So here in aura projectile spell, spawn projectile, we're setting the rotation here.

07:13.940 --> 07:21.440
The rotation is the vector from socket location to projectile target location, convert it to a rotator.

07:21.440 --> 07:25.160
What we can do is override that pitch, but only if we want to.

07:25.190 --> 07:33.470
So I'm going to make a parameter that can go into spawn projectile for overriding the pitch and a boolean

07:33.470 --> 07:35.420
for whether or not we want to do that.

07:35.420 --> 07:40.790
So Spawn Projectile can now take a bool called be override pitch.

07:41.600 --> 07:43.830
We'll set it equal to false by default.

07:43.830 --> 07:47.370
So if we don't pass anything in, nothing will happen.

07:47.370 --> 07:54.660
And then we'll have a float called pitch override and we'll set this to zero by default.

07:54.660 --> 07:57.720
And that way nothing will happen if we don't pass that one in.

07:57.720 --> 08:02.790
And then we'll add this to the CP file right here.

08:03.060 --> 08:09.900
We don't need to set those default values here just in the H file and we'll check if we should override

08:09.900 --> 08:10.710
the pitch.

08:10.710 --> 08:20.820
So for the rotation here, we'll say if be override pitch and if we do, we'll take our spawn transform's

08:20.820 --> 08:22.950
rotation and change it.

08:22.950 --> 08:27.930
In fact, we'll just change the rotation before setting the spawn transform rotation.

08:27.930 --> 08:32.310
So we'll do this right here just after setting the rotation.

08:32.310 --> 08:39.660
If be override pitch, then we'll take rotation, dot pitch and set it equal to pitch override.

08:40.440 --> 08:43.560
That way we can give a little bit of a pitch override.

08:43.560 --> 08:46.200
So let's go ahead and we'll close the editor.

08:48.290 --> 08:53.780
And we'll compile and launch again and set a pitch override for that ranged attack.

08:54.020 --> 08:57.290
This is going to affect our slingshot enemies as well.

08:57.290 --> 08:59.480
So something to keep in mind.

09:00.530 --> 09:01.010
Okay.

09:01.010 --> 09:08.540
So back here in ranged attack, if I check override pitch and I give this a value, say 35, then we

09:08.540 --> 09:11.680
should see those rocks thrown at a 35 degree pitch.

09:11.690 --> 09:13.280
Let's see if that works.

09:14.630 --> 09:15.290
There we go.

09:15.290 --> 09:15.860
Look at that.

09:15.860 --> 09:20.330
They're flying much farther because they're really launching those things.

09:20.450 --> 09:26.000
And that's going to also affect our slingshot enemies, by the way, as I mentioned.

09:26.000 --> 09:30.200
So that could be something we wish to parameterize.

09:30.200 --> 09:35.120
We could also make a ranged attack specific to the character.

09:35.120 --> 09:39.640
We could have a parameter on the character and an interface function to get it.

09:39.650 --> 09:46.250
There are numerous options, but I want to see just really quickly how this affects our slingshot enemy

09:46.250 --> 09:49.490
and we may find a value that works for both of them.

09:49.490 --> 09:54.980
So I'm going to go to Goblin Slingshot, drag in a goblin slingshot and press play.

09:57.340 --> 10:02.290
And of course, my goblin slingshot is behaving like a melee attacker.

10:02.290 --> 10:09.340
And that's because if I right click on it and edit Goblin, Slingshot and search for character class.

10:09.370 --> 10:11.610
Sure enough, it's set to Warrior.

10:11.620 --> 10:13.720
I want it set to Ranger.

10:13.750 --> 10:15.700
Now it'll act like a ranger.

10:16.970 --> 10:18.020
There we go.

10:18.260 --> 10:20.870
So it's a little bit high.

10:20.900 --> 10:25.100
I think it's a little high for the rock to actually it looks good for the rock.

10:25.250 --> 10:26.900
And I think.

10:28.190 --> 10:30.260
Our enemies pitch.

10:31.220 --> 10:33.200
For the slingshot is a little high.

10:34.270 --> 10:41.080
Now, realistically, you could calculate the distance between them and calculate the correct pitch

10:41.080 --> 10:43.720
that would give you an accurate shot.

10:43.780 --> 10:48.860
And that would be a bit of a kind of physics problem to solve, which would be pretty fun.

10:48.880 --> 10:50.320
I'm not going to go that deep.

10:50.320 --> 10:56.950
I'm just going to take my range attack and set the pitch override to 25 and call it done.

10:56.950 --> 10:58.780
But take it as an optional challenge.

10:58.780 --> 11:02.650
If you'd like to calculate the pitch dynamically based on distance.

11:02.650 --> 11:04.290
But I think this is good.

11:04.300 --> 11:11.620
This gives you a bit of a distance that will be considered dangerous for you that you can try to avoid.

11:13.650 --> 11:14.550
Perfect.

11:17.050 --> 11:22.390
And of course, if we eliminate some of these demons, if we don't die in the process.

11:23.120 --> 11:26.150
Well, then we'll get more demons spawned.

11:26.150 --> 11:27.830
But it looks like I died, so.

11:28.040 --> 11:30.960
Okay, well, we did what we set out to do.

11:30.980 --> 11:33.650
We now have a minion count.

11:33.650 --> 11:41.000
And as long as that minion count gets down to below the minion count threshold, we get more minions.

11:41.000 --> 11:43.730
And I'm just going to really quickly test that.

11:43.760 --> 11:50.630
This is a little bit harder with all rock throwing enemies, but we're going to manage and once we get

11:50.630 --> 11:55.900
more powerful abilities, then we won't be so overwhelmed.

11:55.910 --> 12:01.190
Okay, we're down to one and let's see if we can get that summon ability.

12:01.220 --> 12:02.320
There it is.

12:02.330 --> 12:03.680
We have the summon ability.

12:03.710 --> 12:04.610
Perfect.

12:05.060 --> 12:06.290
Excellent job.

12:06.320 --> 12:11.720
In the next video, we'll work on summoning those minions in a more attractive manner rather than just

12:11.720 --> 12:12.730
popping in.

12:12.740 --> 12:15.350
We'll be adding some juice to our game.

12:15.530 --> 12:16.370
Excellent.

12:16.370 --> 12:18.140
I'll see you in the next video.
