WEBVTT

00:06.820 --> 00:07.820
Welcome back.

00:07.840 --> 00:12.250
Now we have some demon enemies, but we'd like to summon these.

00:12.250 --> 00:18.970
I'd like this to be part of a special ability for our shaman, where our shaman summons a bunch of little

00:18.970 --> 00:20.200
demon minions.

00:20.350 --> 00:23.710
So for that reason, I'm going to close all of these tabs.

00:24.400 --> 00:32.650
And just to remind you what that summon animation looks like for our shaman, we can go to assets,

00:32.650 --> 00:38.960
enemies, shaman animations and check out Shaman summon.

00:38.980 --> 00:41.410
And this is what it looks like.

00:41.410 --> 00:50.200
So what I'd like is an ability that will play this as a montage, perhaps, and choose a number of points

00:50.200 --> 00:54.580
in front of the shaman at which to spawn little demons.

00:54.580 --> 00:57.730
And those demons can go do its bidding.

00:58.150 --> 01:05.470
So in this video, we're going to get started with that by creating the ability and devising an algorithm

01:05.470 --> 01:09.550
to choose spawn locations for each of these demons.

01:09.550 --> 01:11.830
So let's go ahead and get started.

01:11.830 --> 01:16.480
Now I'm going to need a C plus plus class for a new ability for the shaman.

01:16.480 --> 01:23.290
So I'm going to go to C plus plus classes or a public ability system abilities, and I'm going to make

01:23.290 --> 01:24.670
a new ability.

01:24.670 --> 01:28.630
Now, this particular ability is just summoning creatures.

01:28.630 --> 01:31.210
It's not really spawning projectiles.

01:31.210 --> 01:33.970
It's not really an attack per se.

01:34.000 --> 01:41.560
So I'm going to base this on a gameplay ability as it doesn't really need a damage variable.

01:41.560 --> 01:48.280
So I'm going to right click on aura gameplay ability and create a C plus plus class derived from aura

01:48.310 --> 01:49.540
gameplay ability.

01:49.540 --> 01:53.410
And this is going to be a summon ability.

01:53.440 --> 02:01.930
So I can call this summon ability, we can call it aura summon ability if we want to.

02:01.930 --> 02:06.490
In a sense that aura prefix's most of the things in this game.

02:06.730 --> 02:10.840
So we'll call this aura summon ability, we'll create the class.

02:11.510 --> 02:18.770
And we'll close the editor and I'm going to go ahead and close all tabs here and just open my abilities

02:18.770 --> 02:27.020
folder, get my aura, summon ability open and we can start thinking about what to do with our aura

02:27.020 --> 02:27.890
summon ability.

02:27.890 --> 02:30.770
Now, I don't want to override, activate ability.

02:30.800 --> 02:37.130
What I'd rather do is create a blueprint callable function and script out the ability logic in the blueprint

02:37.130 --> 02:42.170
as we've been doing, as this is the way that gas is meant to be used.

02:42.350 --> 02:49.550
So I'm going to make a nice blueprint callable function to calculate the spawn locations.

02:49.550 --> 02:51.620
So this is a summon ability.

02:51.620 --> 02:54.590
We need an array of spawn locations.

02:54.590 --> 03:01.310
It could be an array with a single element in it, as I'd like, this ability to be sort of configurable

03:01.310 --> 03:02.870
with parameters and all.

03:02.870 --> 03:10.760
So first I'm going to make a public section and we'll make a function that returns a t array of vectors.

03:10.760 --> 03:18.690
So t array of F vector and this is going to be called get spawn locations.

03:18.990 --> 03:27.000
So get spawn locations is how we're going to know where we should spawn our little demon minions.

03:27.000 --> 03:29.880
I'm going to refer to them as minions in this ability.

03:29.880 --> 03:33.150
So that way it's not specific to demons per se.

03:33.180 --> 03:39.960
It's really whatever minion you choose, whatever enemy class or whatever character class you choose

03:39.960 --> 03:40.860
to spawn.

03:40.950 --> 03:48.030
So as far as this ability is concerned, we're going to call that a minion whenever we spawn something.

03:48.210 --> 03:55.320
Now this is going to be a new function with Blueprint Callable and get Spawn locations is going to be

03:55.320 --> 04:02.430
an algorithm that we devise to get a number of locations around our enemy in the front of it.

04:02.580 --> 04:10.500
And I'm going to want several variables to determine how this algorithm is going to behave.

04:10.860 --> 04:13.890
So for one, we need a number of minions.

04:13.890 --> 04:17.760
That's going to be an int 32 called num minions.

04:17.940 --> 04:20.160
It could be num minions to spawn.

04:20.160 --> 04:21.120
ET cetera.

04:21.120 --> 04:30.720
Now I'm going to set it equal to a value by default, let's say five, but this should be configurable,

04:30.720 --> 04:34.410
so it'll be a new property add anywhere.

04:36.780 --> 04:38.160
Category.

04:39.630 --> 04:45.630
And these are all going to be properties under the summoning of Minions.

04:45.630 --> 04:47.640
So we're going to call this summoning.

04:47.850 --> 04:53.730
So we have a number of minions, so we need to know what class to spawn or class is if we're going to

04:53.730 --> 04:59.850
spawn multiple, even potentially different types of enemies or characters.

04:59.850 --> 05:06.720
So we need to have an array and we can make this a t array of characters or pawns, but it should be

05:06.720 --> 05:14.640
a subclass of I'll just make it a T subclass of a pawns that we can spawn and we're going to call this

05:14.640 --> 05:16.020
minion classes.

05:16.650 --> 05:19.620
And of course this needs to be editable.

05:19.620 --> 05:21.900
We'll make this edit anywhere.

05:21.900 --> 05:27.480
In fact, this is a gameplay ability, so I don't see any need to make it edit anywhere.

05:27.480 --> 05:30.330
We can make them edit defaults only instead.

05:30.600 --> 05:33.510
So we have our minion classes now.

05:33.510 --> 05:42.040
I'd like a minimum and maximum for the distance from our shaman or whoever's doing the spawning.

05:42.040 --> 05:47.920
I want a minimum and maximum distance away that we should spawn our minions at.

05:47.920 --> 05:57.520
So I'm going to make a float called Min Spawn Distance and I'll just give it a default value of say,

05:57.550 --> 06:06.250
50 and a float called Max spawn distance and I'll give it a default of say, 250.

06:06.250 --> 06:09.820
And these both also get the same view property.

06:10.740 --> 06:17.850
So we know how many minions, we know how far they should be spawned, but we also need a spread.

06:17.880 --> 06:21.680
I really don't want to spawn these all around the shaman.

06:21.690 --> 06:25.140
I'd rather them all be spawned relatively in front of the shaman.

06:25.140 --> 06:29.220
So I want an angle of spread for spawning.

06:29.220 --> 06:32.520
And I'm going to call this spawn spread.

06:32.550 --> 06:33.690
It's a float.

06:35.480 --> 06:37.580
And I'm going to set this to 90.

06:37.580 --> 06:46.460
So basically we have a 90 degree spread and we'll fan out our spawn locations within that 90 degrees.

06:46.550 --> 06:49.130
But this, of course, will also be editable.

06:49.370 --> 06:49.700
Okay.

06:49.700 --> 06:52.700
So we have a number of parameters and a function.

06:52.730 --> 06:54.560
Let's implement this function.

06:54.560 --> 07:02.600
I'm going to generate a definition and all I want to do is generate this t array and return it, but

07:02.600 --> 07:08.180
also probably draw some debug shapes so we can visualize what this looks like.

07:08.210 --> 07:10.520
Now I'd like to take this in steps.

07:10.520 --> 07:16.450
First, I want to visualize that spread and the minimum and maximum distances.

07:16.460 --> 07:21.680
So the first step I think is to get the actor forward vector.

07:21.860 --> 07:29.150
I'm going to make a const f vector called forward and get the forward vector of the avatar actor.

07:29.150 --> 07:36.180
So I'm going to get Avatar actor from actor info and call get actor forward vector.

07:36.390 --> 07:38.400
So we have the forward vector.

07:38.400 --> 07:41.310
We can also get the actor location as well.

07:41.310 --> 07:48.240
I'll call it location and call get Avatar actor from actor info, get actor location.

07:48.240 --> 07:51.140
So we have forward and we have location.

07:51.150 --> 07:57.720
Now we can rotate vectors, for example, we can take the forward vector and we can rotate it by using

07:57.720 --> 07:59.670
rotate angle axis.

07:59.700 --> 08:05.880
Now if I use rotate angle axis, I have to specify how much to rotate my vector.

08:05.880 --> 08:10.200
Now I can rotate it by half of the spread and that's going to rotate it.

08:10.200 --> 08:14.300
If spawn spread is 90 degrees, it'll rotate it by 45.

08:14.310 --> 08:18.450
So I'm going to take spawn spread and divide by two.

08:18.450 --> 08:24.660
That will give me 45 when spawn spread is 90 and I'd like to rotate about the Z axis.

08:24.660 --> 08:32.130
So what I can do is I can take F vector up vector that gives me the vector pointing up and this gives

08:32.130 --> 08:34.590
me the forward vector, but rotate it.

08:34.590 --> 08:41.550
I'm going to store this in a local variable for now, const f vector and I'll call this left of spread.

08:41.760 --> 08:43.650
So it's to the left of our spread.

08:43.650 --> 08:46.080
It's the left most boundary.

08:46.230 --> 08:51.660
And what I can do is I can draw this as a debug arrow or a debug line.

08:51.750 --> 08:58.500
I like debug arrows as they're directional and there's a way to draw a debug arrow with you.

08:58.530 --> 09:00.360
Kismet System Library.

09:02.650 --> 09:08.830
And the function is draw debug arrow and this requires a few parameters.

09:08.830 --> 09:15.190
First, it needs a world context object we can pass in get Avatar actor from actor info.

09:15.460 --> 09:22.360
Now for the start of the line that's going to be location for the end of the line.

09:22.360 --> 09:26.860
That will be location plus left of spread.

09:29.010 --> 09:36.870
But left of spread is a unit vector as our forward vector is a unit vector, a vector of length one.

09:36.870 --> 09:41.520
So I'm going to scale this and I'd like to scale it by my max.

09:42.630 --> 09:44.090
Spawn distance.

09:44.100 --> 09:49.770
So our line end is location plus left of spread times.

09:49.770 --> 09:51.330
Max spawn distance.

09:51.360 --> 09:54.900
Now, for arrow size, we can just put whatever we want here.

09:54.900 --> 09:57.270
I'm just going to put a four.

09:58.270 --> 09:59.230
Dot f.

09:59.650 --> 10:05.110
Now for the color, I'm going to have a vector for left of spread and right to spread, and I'm going

10:05.110 --> 10:07.910
to make them different colors so we know which one is which.

10:07.930 --> 10:15.100
So for left of spread, I'm going to make it an F linear color with green and then we'll really see

10:15.100 --> 10:18.280
if it's to the left or to the right of the spread or not.

10:18.280 --> 10:20.080
And for the duration.

10:20.110 --> 10:23.860
I'm going to use three seconds.

10:25.890 --> 10:28.860
And there we have our debug arrow.

10:28.980 --> 10:30.450
So we have left of spread.

10:30.450 --> 10:36.590
But I'd like to create another one called Right of Spread and I'd like to rotate it the other way.

10:36.600 --> 10:44.910
So this one I'm going to call right of spread and instead of rotating it by spawn spread divided by

10:44.910 --> 10:51.690
two, we're going to rotate it by negative spawn spread divided by two around the up vector, and we're

10:51.690 --> 10:53.760
going to draw the debug arrow.

10:53.850 --> 10:59.820
But instead of using left of spread, we're going to use right of spread and we're also going to change

10:59.820 --> 11:00.590
the color.

11:00.600 --> 11:04.110
Let's make the color something else like gray.

11:05.770 --> 11:06.130
Okay.

11:06.130 --> 11:09.780
So I think we're going to want to test out how this works so far.

11:09.790 --> 11:16.300
So what we can do is we can choose to return an empty array for now.

11:16.660 --> 11:19.030
So return t array.

11:20.540 --> 11:22.130
Of F vectors.

11:24.560 --> 11:30.170
And we'll just use parentheses there so that we can just return an empty array.

11:30.590 --> 11:33.110
I'm not really concerned with the array just yet.

11:33.110 --> 11:38.810
I just want to take a look at what our geometry looks like for these vectors we've calculated.

11:38.810 --> 11:41.420
So let's go ahead and run and debug mode.

11:42.800 --> 11:44.510
Okay, so we're back in the editor.

11:44.510 --> 11:47.870
We're going to make a blueprint based on our new gameplay ability.

11:47.870 --> 11:51.500
And this will go into blueprints, ability, system enemy.

11:51.500 --> 11:56.660
And really, it doesn't have to go into enemy, but we're going to make one for the shaman specifically.

11:56.660 --> 12:04.910
So we'll go into abilities, we'll right click create Blueprint class and use aura summon ability.

12:06.320 --> 12:12.950
We'll select that and call this GA underscore summon ability.

12:14.100 --> 12:15.720
We'll go ahead and open this.

12:16.450 --> 12:22.840
And when this ability is activated, I'm going to right click and I'm going to call our blueprint callable

12:22.840 --> 12:26.320
function, get spawn locations.

12:26.740 --> 12:30.910
And from there we're just going to see a couple of debug arrows.

12:30.940 --> 12:36.880
Now, if we want to see this actually happen, if we want to see this ability activated, we're going

12:36.880 --> 12:39.190
to have to give it a tag.

12:39.190 --> 12:46.000
If we go to class defaults and for the ability tags, we're going to give it the abilities attack tag

12:46.000 --> 12:50.980
just so that it already works with our behavior tree task attack.

12:50.980 --> 12:55.240
And now we just need to give this to our elementalist enemy type.

12:55.240 --> 13:01.300
So what I'm going to do is go into blueprints, ability system data and open character class info and

13:01.300 --> 13:05.380
for the elementalist instead of the enemy Firebolt.

13:05.380 --> 13:11.140
I'm going to change this to a summon ability so it's not going to fire firebolts anymore.

13:11.140 --> 13:12.880
At least not for now.

13:12.910 --> 13:15.310
Don't worry, it will in the future.

13:15.310 --> 13:17.240
We're just seeing how this works.

13:17.240 --> 13:19.490
We're going to activate the summon ability.

13:19.520 --> 13:22.220
So let's give this a try.

13:22.220 --> 13:28.850
I'm going to remove these demons and just add a shaman.

13:28.850 --> 13:35.690
So we're going to go into the shaman folder, bring that in, and as soon as BT attack the behavior

13:35.690 --> 13:40.910
tree task is executed and it's going to activate abilities by Tag.

13:40.910 --> 13:46.280
And because this has the attack tag, we should see these spawn locations.

13:46.280 --> 13:48.500
So I'm going to save all press play.

13:49.280 --> 13:54.420
And there we see the spread and we see the two different colored vectors.

13:54.440 --> 13:57.560
Now we call the green one left of spread.

13:57.560 --> 14:00.080
And from Ora's point of view, it is the left.

14:00.080 --> 14:03.910
But from the enemy's point of view, that's actually the right, isn't it?

14:03.920 --> 14:07.140
So we kind of got those mixed up.

14:07.160 --> 14:11.720
The first one is the right, the green one, that is.

14:11.750 --> 14:13.590
And the gray one is the left.

14:13.610 --> 14:18.140
So what we can do is rename this one to right of spread.

14:18.500 --> 14:21.020
So the first one is right of spread.

14:21.350 --> 14:25.130
And the second one here, this is left of spread.

14:26.240 --> 14:29.750
So we're going to just swap their names.

14:29.750 --> 14:35.550
And that way we're looking at this from the point of view of the enemy, the shaman.

14:35.570 --> 14:44.180
So that Green Arrow is actually the one to the right, as we can see when playtesting there, that's

14:44.180 --> 14:46.640
the right the gray one is the left.

14:47.850 --> 14:53.520
Okay, so it looks like we have a pretty good max distance.

14:53.550 --> 15:02.190
We could probably up that to about 300 and we can't really see how far away the min distance is, but

15:02.190 --> 15:07.950
I'm assuming we'll probably want to up that to to about maybe 75 to 100.

15:07.980 --> 15:12.420
So we'll just tweak these parameters in some inability.

15:12.420 --> 15:17.850
We'll go to class defaults, but we can always change their defaults in C plus plus as well.

15:17.850 --> 15:25.680
But I'm going to use a min spawn distance of 75 and a max of 300, but I'd like to also take a look

15:25.710 --> 15:29.580
at some debug spheres at those distances.

15:29.580 --> 15:37.440
So what I'm also going to do is after drawing these debug arrows, I'm going to draw debug spheres at

15:37.440 --> 15:43.080
the min and max distances along these lines, right of spread and left of spread.

15:43.110 --> 15:47.130
So I'm going to actually call draw debug sphere.

15:49.060 --> 15:52.060
The first input is the world I'm going to call Git World.

15:52.270 --> 15:54.730
Next, we have the center of the sphere.

15:54.760 --> 15:59.770
Now this is going to be at the location of Location Plus.

15:59.920 --> 16:03.400
And I'm going to add right of spread only.

16:03.400 --> 16:08.350
I'm going to scale right of spread by that min spawn distance.

16:09.850 --> 16:13.090
This way we can visualize how far away it is.

16:13.120 --> 16:15.570
Now, the radius of this sphere can be small.

16:15.580 --> 16:17.530
I'm going to make it about 15.

16:17.530 --> 16:19.450
Number of segments can be 12.

16:19.450 --> 16:22.420
I always use 12 F color can be red.

16:24.220 --> 16:27.130
And persistent lines can be false.

16:27.700 --> 16:29.860
Lifetime can be three seconds.

16:31.480 --> 16:37.300
So we're going to draw that debug sphere, but I'm also going to draw another sphere at the max distance.

16:37.300 --> 16:42.910
So I'm going to copy and paste this and the only thing I'm going to change is from min spawn distance.

16:42.910 --> 16:48.460
We're changing to max spawn distance, so we'll see a sphere at the min spawn distance.

16:48.460 --> 16:54.820
This will allow us to know how far away or how close the demons will be once we start spawning them.

16:54.820 --> 16:56.440
Or the minions, I should say.

16:56.680 --> 17:02.440
Now we're going to do this at the right of spread vector, but we're going to spawn two spheres along

17:02.440 --> 17:05.470
the line of the left of spread vector as well.

17:05.470 --> 17:10.660
So I'm going to copy those two lines, paste them here and change right of spread to left of spread.

17:10.660 --> 17:13.060
And now we're going to see what this looks like.

17:13.060 --> 17:18.580
So I'm going to go ahead and close the editor and run in debug mode again.

17:19.770 --> 17:22.610
Okay, I'll go ahead and open up our ability.

17:22.620 --> 17:26.990
But really I just want to press play and see those debug spheres.

17:27.000 --> 17:31.800
Now, as I suspected, the min spawn distance is a little close.

17:31.800 --> 17:38.400
I don't want to spawn any minions that close so we can go back to summon ability and change min spawn

17:38.400 --> 17:39.270
distance.

17:39.270 --> 17:42.320
I think 150 is actually probably good.

17:42.330 --> 17:44.610
Let's see what 150 looks like.

17:44.850 --> 17:46.710
That's probably better.

17:46.710 --> 17:54.630
And I could probably even push that max spawn distance out a little more to say maybe even 400.

17:54.810 --> 18:02.700
And that way we'll have a nice area here and we'll spawn enemies within that area.

18:02.910 --> 18:07.470
Now we want a spread, I want an even spread.

18:07.500 --> 18:16.140
So I want to spawn an enemy somewhere along the lines of that left vector and somewhere along the lines

18:16.140 --> 18:17.700
of that right vector.

18:17.700 --> 18:22.390
And I'd like to spawn some enemies all in between.

18:22.390 --> 18:29.890
So I kind of want to take this spread and divide it by my number of minions that I want to spawn, and

18:29.890 --> 18:37.270
that should give me the number of vectors along which my minions can be spawned.

18:37.540 --> 18:41.590
So what I'm going to do is I'm going to close the editor.

18:42.550 --> 18:47.920
And I'd like to take my spread and divide it by the number of minions I want to spawn.

18:48.130 --> 18:53.590
This will give me the number of vectors that I need to calculate.

18:53.860 --> 18:55.910
So I'm going to have a float.

18:55.930 --> 19:01.780
It'll be a const float and this will be called Delta Spread, which is going to be my spawn spread,

19:01.780 --> 19:09.310
which by default is 90 degrees divided by my num minions, which by default is five.

19:09.340 --> 19:11.770
So 90 degrees divided by five.

19:11.800 --> 19:19.570
This will be the angle between each of the vectors that I want to spawn minions along.

19:19.600 --> 19:29.590
Now, because I have a num minions, I'm going to want to do a for loop here and draw debug arrows in

19:29.590 --> 19:37.630
a spread spreading out like a fan and I want to start at right of spread and continue rotating by delta.

19:37.630 --> 19:42.710
Spread each iteration of the for loop and just draw some debug arrows.

19:43.250 --> 19:44.480
So here's what I'm going to do.

19:44.480 --> 19:54.170
I'm going to make a regular for loop with an int 32 called I set it equal to zero and as long as I is

19:54.170 --> 19:56.900
less than num minions I want to continue.

19:57.290 --> 20:00.470
Didn't mean to autocomplete that so it's going to be.

20:01.330 --> 20:06.150
Num minions and we're going to use I plus plus.

20:07.120 --> 20:12.940
So at first I is zero and I want to draw that right of spread vector.

20:13.030 --> 20:18.850
This is going to be sort of my beginning vector, my starting vector.

20:18.850 --> 20:21.880
So I'm going to move it just up above the for loop.

20:23.010 --> 20:25.950
And I'm going to calculate a direction vector.

20:25.950 --> 20:28.800
So const F vector.

20:30.410 --> 20:34.520
Call direction and it's going to be right of spread.

20:37.900 --> 20:40.540
But I'm going to take right of spread and rotate it.

20:40.540 --> 20:48.070
So I'm going to use rotate angle axis and I'm going to rotate it by delta spread times I.

20:48.100 --> 20:53.710
So the first time I will be zero, the first iteration of the loop and it will be just right of spread.

20:53.710 --> 20:54.940
We won't rotate at all.

20:54.970 --> 20:59.620
But the second iteration of the loop, we're going to rotate by delta spread and so on.

20:59.740 --> 21:08.020
And we're going to rotate about the up vector, so F vector up vector, and then we can simply draw

21:08.020 --> 21:09.460
that debug arrow.

21:09.460 --> 21:12.970
So I'm going to copy that line, paste it here.

21:13.000 --> 21:22.570
Only the debug arrow is going to start at location and end at location plus direction times max spawn

21:22.570 --> 21:23.490
distance.

21:23.500 --> 21:30.910
So now we'll be doing five lines because num minions is five and now I don't need those other draw debug

21:30.910 --> 21:39.290
arrow function calls, so I'm going to comment those out and I can simply run this and see what these

21:39.290 --> 21:40.490
vectors look like.

21:40.490 --> 21:42.170
So I'm going to go ahead and hit debug.

21:42.910 --> 21:45.280
So they should all be green arrows.

21:45.460 --> 21:50.320
But now we can make sure that we're getting an even spread of these vectors.

21:50.470 --> 21:53.200
So I can go ahead and hit play.

21:53.200 --> 21:58.030
I don't really need to keep hitting the open button kind of a habit at this point, but I'm going to

21:58.030 --> 22:02.890
press play and see and it looks like we've rotated the wrong way.

22:02.890 --> 22:11.290
So that's why these debug arrows and shapes are so important because then we can really get to know

22:11.290 --> 22:14.830
the geometry and make sure that we're not doing it wrong.

22:14.860 --> 22:22.960
So we could either start spreading or rotating the other way or we can start with left of spread.

22:23.230 --> 22:29.970
If we start with left of spread, then really all we need to do is replace the name with left of spread.

22:29.980 --> 22:35.710
Arguably don't even need that step, but we need spawn spread here to be negative.

22:35.710 --> 22:43.640
So we're rotating the other way and then direction will be left of spread, rotated by the same direction.

22:43.640 --> 22:46.280
So we're actually rotating in the same direction.

22:46.280 --> 22:52.250
We're just starting from a different orientation and now we don't need this left of spread.

22:52.250 --> 22:53.690
So I'm going to comment it out.

22:53.840 --> 22:54.320
Now.

22:54.320 --> 23:00.740
What I'd like to do actually is take our two calls to draw debug sphere, cut them out and paste them

23:00.740 --> 23:06.380
inside the for loop and replace right of spread with direction.

23:06.590 --> 23:11.150
That way we'll get these spheres drawn and I'm going to make them even smaller.

23:11.150 --> 23:17.000
I'm going to give them a radius of ten and then I can go ahead and comment out all the rest of these

23:17.000 --> 23:17.690
lines.

23:17.690 --> 23:21.670
So now we should see spheres all along each of our lines.

23:21.680 --> 23:23.150
Let's give this a try.

23:24.450 --> 23:24.750
Okay.

23:24.750 --> 23:25.950
I'm going to press play.

23:26.940 --> 23:33.060
And now we see something a little bit more along the lines of what we expected.

23:33.270 --> 23:36.960
So here's what this spread means, at least for me.

23:36.960 --> 23:44.250
This is what I have in mind, is I want to spawn five minions and each of them will be spawned somewhere

23:44.250 --> 23:50.070
along one of these lines between the min spawn distance and the max spawn distance.

23:50.070 --> 23:58.020
So we're going to pick a random location along each of these lines, and I'm going to add those to an

23:58.020 --> 24:01.170
array that our function is going to return.

24:01.290 --> 24:10.440
So what I'm going to do is I'm going to go ahead and pick a random location along the line in the for

24:10.440 --> 24:10.980
loop.

24:11.220 --> 24:16.440
So I'm going to create a const f vector called location.

24:16.440 --> 24:23.850
Actually, I'm going to call this chosen spawn location and it's going to be equal to location.

24:23.850 --> 24:28.410
That's the shaman's location plus direction.

24:28.590 --> 24:33.450
And we're going to multiply direction by a random number in range.

24:33.450 --> 24:42.210
We're going to use F math rand range and we'll use F rand range for the float version and the min is

24:42.210 --> 24:44.520
going to be min spawn distance.

24:44.550 --> 24:52.200
The max will be max spawn distance and that way we'll get some random value between Min and Max that

24:52.200 --> 24:56.250
will be scaling that direction vector by and adding to location.

24:56.250 --> 25:03.150
So this will be our chosen location and we're going to draw a debug sphere to show that spawn location.

25:03.150 --> 25:09.390
So what I'm going to do is right after chosen spawn location, we'll draw the debug sphere and we're

25:09.390 --> 25:12.900
going to draw it at our chosen spawn location here.

25:12.990 --> 25:14.550
I'm going to make it a little bigger.

25:14.550 --> 25:18.240
Let's make it about 18 in duration.

25:18.240 --> 25:20.430
We'll give it a different color.

25:20.520 --> 25:24.480
I'm going to choose Cyan and our other spheres.

25:24.480 --> 25:26.310
I'm going to draw them even smaller.

25:26.310 --> 25:28.900
We're going to draw them at five now.

25:29.260 --> 25:37.300
So now we should be able to visualize our spawn locations and at this point we can actually start returning

25:37.300 --> 25:40.660
something because now we have chosen spawn locations.

25:40.660 --> 25:49.690
We can create a local array just outside the for loop t array of F vectors called spawn locations.

25:50.170 --> 25:54.970
And each time we choose a spawn location, we can add that to spawn locations.

25:54.970 --> 25:57.370
So we can say spawn locations, dot add.

25:58.010 --> 26:05.420
And we can add chosen spawn location and at the end of the function we can return spawn locations.

26:05.420 --> 26:10.430
So really all this stuff that I've commented out is now no longer necessary.

26:10.460 --> 26:17.750
I can remove it and we now have a whole bunch of debug stuff that I'm just going to keep all together

26:17.750 --> 26:18.830
right here.

26:19.460 --> 26:24.780
And let's go ahead and see what those spawn locations end up looking like.

26:24.800 --> 26:26.780
So I'm going to hit the debug button.

26:28.440 --> 26:30.180
And we're just going to hit play.

26:30.770 --> 26:32.240
And there we go.

26:32.240 --> 26:36.860
We have random spawn locations all about that spread.

26:36.950 --> 26:38.720
Pretty cool, right?

26:39.600 --> 26:45.600
So this is nice because now we can kind of see the locations that would be chosen by this algorithm.

26:45.600 --> 26:48.510
That one was a bit of a wider out spread.

26:48.540 --> 26:50.460
This one was a little more random.

26:50.460 --> 26:51.600
So pretty cool, right?

26:51.600 --> 26:59.100
I think this is a nice little algorithm to get, you know, five different locations, but we parameterized

26:59.100 --> 26:59.280
it.

26:59.280 --> 27:00.990
It doesn't have to be five.

27:01.020 --> 27:04.650
We can go back into our gameplay ability.

27:04.650 --> 27:11.910
Let's go into enemy abilities and gain some inability and we could easily change these parameters.

27:11.910 --> 27:14.760
We could change the number of minions to eight.

27:14.820 --> 27:19.500
We can change the spawn spread to 120 and if we do that.

27:20.470 --> 27:27.100
Now we can see that there's an even wider spread with more minions, more enemies to spawn, or at least

27:27.100 --> 27:30.250
more locations to potentially spawn enemies at.

27:30.280 --> 27:30.940
Right.

27:30.940 --> 27:36.880
And that's kind of cool because you could make some kind of formula related to the abilities level,

27:36.880 --> 27:41.590
for example, and then you could spawn more or less enemies based on that.

27:41.620 --> 27:43.570
The possibilities are endless.

27:43.600 --> 27:49.930
I'm going to set the spread back to 90 and the number of minions back to five, and we now have a nice

27:49.930 --> 27:53.440
little algorithm to choose spawn locations.

27:53.440 --> 27:57.750
And that's the first step to spawning enemies with our new spawn ability.

27:57.760 --> 28:00.730
So great job sticking through this video.

28:00.730 --> 28:08.200
It was a little longer, but we did need to devise a little bit of a more complex algorithm.

28:08.200 --> 28:11.040
Not really complex, but more involved, right?

28:11.110 --> 28:12.670
Actually kind of small.

28:12.670 --> 28:15.670
When you remove all the debug stuff, it's not too bad.

28:15.670 --> 28:20.180
But now we have a set of spawn locations and we can use those.

28:20.180 --> 28:22.400
So great job and I'll see you soon.
