WEBVTT

00:07.110 --> 00:08.190
Welcome back.

00:08.220 --> 00:10.800
Now this section is my favorite.

00:10.800 --> 00:16.140
And this is where it's really going to start getting fun because the abilities are where it's at.

00:16.170 --> 00:18.840
These are the heart of the gameplay ability system.

00:18.840 --> 00:25.890
And while yes, we've already created several abilities, I'm really interested in these abilities.

00:25.890 --> 00:33.810
My spells I want to make more than just the Firebolt, because really, this is the only spell that

00:33.810 --> 00:36.690
we've created and we're going to make more.

00:36.690 --> 00:44.520
But before we make more spells like implementing that electrocute spell we created, I also would like

00:44.520 --> 00:48.150
to make leveling up our abilities meaningful.

00:48.330 --> 00:54.470
You see, all we're doing when we spend a point on an ability is we're making it do more damage.

00:54.480 --> 01:01.980
So if I go and, you know, level up to level two and I have my Firebolt selected and I spend a point

01:01.980 --> 01:07.470
on it, yeah, I'm changing a couple things here that depend on the level, but that's it though.

01:07.500 --> 01:09.390
We're just changing numerical values.

01:09.390 --> 01:11.010
We're changing the math involved.

01:11.010 --> 01:12.510
We're not changing anything else.

01:12.510 --> 01:18.240
When I launch my level two Firebolt, it looks exactly the same as a level one Firebolt.

01:18.240 --> 01:24.030
In this section, we're going to make leveling up, have a cosmetic element to it as well.

01:24.030 --> 01:31.260
So if I'm launching a level two Firebolt look, my description even says launch is two bolts of fire.

01:31.290 --> 01:31.890
Right?

01:31.890 --> 01:34.560
And I want to launch two bolts of fire.

01:34.560 --> 01:36.690
I want to deliver on this promise.

01:36.690 --> 01:42.960
And for that reason, we're going to need a bit of a different function for our projectile.

01:42.990 --> 01:50.490
Now, we don't want to mess with the spawn projectile function because our slingshot goblins are using

01:50.490 --> 01:53.580
it, and it works just fine for the slingshot goblin.

01:53.580 --> 01:55.890
It's causing damage, right?

01:55.890 --> 01:58.590
And it's launching a single rock.

01:58.620 --> 02:00.150
That's all it needs to do.

02:00.150 --> 02:03.570
But for my Firebolt, it depends on the level.

02:03.570 --> 02:07.860
And we're going to change some things with our Firebolt.

02:07.860 --> 02:13.380
Now I want you to imagine for a second what this is going to look like.

02:13.380 --> 02:23.310
If I press play and I pause and go ahead and detach and I look at aurra from above, I want Aurra to

02:23.310 --> 02:24.900
launch a Firebolt.

02:25.080 --> 02:26.520
Let's just say it's level one.

02:26.520 --> 02:32.070
If it's level one, I want to launch a Firebolt relatively forward, or at least forward in a sense

02:32.070 --> 02:33.000
of where we're aiming.

02:33.000 --> 02:37.860
Where I clicked over here, I want to launch that fireball towards that direction.

02:37.890 --> 02:43.620
Okay, now let's just say that I've leveled up my Firebolt to level two.

02:43.680 --> 02:45.690
Well, now I'm going to have a spread.

02:45.720 --> 02:52.890
Remember when we calculated random spawn locations for our shaman when our shaman was summoning minions?

02:53.070 --> 02:57.810
We're going to make an algorithm similar to that, but it's going to have some differences.

02:57.930 --> 03:04.050
For one, we're going to have a spread, and if our ability is level two, we're going to launch two

03:04.050 --> 03:06.690
Firebolts spread out.

03:06.720 --> 03:08.880
Now that means we're going to miss.

03:08.880 --> 03:09.210
Right?

03:09.210 --> 03:15.000
Well, not exactly, because our projectiles have projectile movement components.

03:15.000 --> 03:17.850
And those can be homing missiles.

03:17.850 --> 03:20.760
They can have a homing target.

03:20.760 --> 03:23.460
And if we click somewhere I want to home in on it.

03:23.460 --> 03:30.000
So even though these two firebolts are going to launch out into seemingly different directions, they're

03:30.000 --> 03:32.550
going to come back in on what we clicked on.

03:32.640 --> 03:35.310
They're going to home in on their target.

03:35.310 --> 03:42.750
And if we click on a enemy, for example, then they can even home in on a moving actor as well.

03:42.750 --> 03:45.900
So that's something we're going to implement on our firebolts.

03:45.900 --> 03:48.360
They're now going to be homing projectiles.

03:48.660 --> 03:53.130
Now, the first step to this is the math behind that spread.

03:53.460 --> 03:59.610
We know an algorithm that's sort of similar to what we want, but we're going to see that this will

03:59.610 --> 04:01.590
have a few differences as well.

04:01.590 --> 04:09.450
And when doing these algorithms, it's always nice to be able to visualize with debug shapes and arrows

04:09.450 --> 04:10.320
and things.

04:10.320 --> 04:15.900
And so that's where we're going to start in this video is we're going to make a function that can start

04:15.900 --> 04:19.620
visualizing the spread for spawning these projectiles.

04:19.620 --> 04:26.580
And that's going to be in our Firebolt class because this is very much unique to the Firebolt.

04:26.580 --> 04:30.630
And if I go ahead and just close all tabs.

04:31.290 --> 04:34.860
And just open up my aura Firebolt spell.

04:34.890 --> 04:38.970
Well, so far all it does is set the description text.

04:38.970 --> 04:43.440
But now we're going to have a more interesting function to call.

04:43.470 --> 04:45.720
We're going to have spawn projectiles.

04:45.870 --> 04:55.590
Now yes, we are inheriting from Aura projectile spell which indeed has a spawn projectile function.

04:55.590 --> 04:56.040
Right.

04:56.040 --> 05:03.060
But this is again what we said earlier about this function is we don't really want to mess with it because,

05:03.060 --> 05:08.970
well, our slingshot enemies are using it and it works just fine for slingshot enemies.

05:08.970 --> 05:12.870
So we can maybe take a look at it to see how we did some things.

05:12.870 --> 05:20.220
But Aura Firebolt is going to have a brand spanking new spawn projectile spell, and we can call it

05:20.220 --> 05:24.300
spawn projectiles with an S because it's going to spawn multiple.

05:24.480 --> 05:32.340
So we'll call this spawn projectiles with an S, and let's look at our projectile spell.

05:32.340 --> 05:35.870
We'll see that it needs a projectile target location.

05:35.880 --> 05:37.440
Yes it does.

05:37.470 --> 05:46.290
We see that it takes a socket tag because it needs to know what socket to spawn our projectile from,

05:46.530 --> 05:48.810
and we override the pitch.

05:48.840 --> 05:55.740
If this is true with a pitch override, we could do those same things in our projectile if we'd like.

05:55.770 --> 06:01.620
Those are all things that we could use, but we're also going to need a homing target, which is an

06:01.620 --> 06:02.310
actor.

06:02.310 --> 06:08.520
In the case where we click on an actor, in the case where we click actually on an actor specifically,

06:08.520 --> 06:12.740
that's an enemy we have interfaces and such that we can use to check.

06:12.750 --> 06:18.180
So if we click on something that's, say, implementing the combat interface, for example, then we

06:18.180 --> 06:21.830
can set that as our homing target for our projectiles.

06:21.840 --> 06:24.240
Otherwise we'll have to do something else.

06:24.240 --> 06:33.150
So in addition to these parameters we're also going to need that actor for an optional homing target.

06:33.420 --> 06:43.710
So we'll start by adding a const f vector called projectile target location a socket tag, and perhaps

06:43.710 --> 06:47.310
override pitch and pitch override.

06:47.310 --> 06:51.120
And we'll stick those in for spawn projectiles.

06:51.120 --> 06:56.460
But it's also going to get another input of type A actor pointer.

06:56.550 --> 07:00.630
And this will be the homing target.

07:03.440 --> 07:06.800
So let's go ahead and generate the definition for this.

07:06.800 --> 07:11.390
And spawn projectiles is going to be simple at first.

07:11.420 --> 07:13.430
Now we're going to start doing some math.

07:13.430 --> 07:17.540
And we can start by getting the locations and directions of things.

07:17.540 --> 07:23.180
And if we look at our projectile spell, we have a pretty good example of things that we're going to

07:23.180 --> 07:24.650
want to start with.

07:24.860 --> 07:27.980
For one, we're going to check to see if we're on the server.

07:27.980 --> 07:29.870
If we're not, we'll return.

07:29.870 --> 07:36.530
And then we see that we get the socket location using the interface function, get combat socket location

07:36.530 --> 07:38.500
passing in that socket tag.

07:38.510 --> 07:45.140
If there is a pitch override, we override the pitch of the rotation that we got from doing some vector

07:45.140 --> 07:48.320
math from the socket location to the target.

07:48.470 --> 07:50.810
Now we have this rotation, right.

07:50.810 --> 07:55.310
We can copy all this and we can paste it here in Aura Firebolt.

07:55.640 --> 08:02.240
Now what I'd like to do is just draw a debug arrow in the direction of this rotation.

08:02.240 --> 08:02.810
Right.

08:02.810 --> 08:10.820
I'm going to use U Kismet system library draw debug arrow for that.

08:10.850 --> 08:17.060
So for the world context object I'll get the avatar and pass that in.

08:17.060 --> 08:19.520
And we need a start.

08:19.520 --> 08:22.340
The line start will be at the socket location.

08:23.390 --> 08:29.420
The line end is going to be at socket location plus some vector.

08:29.420 --> 08:37.820
Well I'm just going to get rotation dot vector and multiply that by say 150, maybe just 100.

08:37.820 --> 08:46.880
Actually for the arrow size we'll just put a five for the linear color f linear color green.

08:48.930 --> 08:52.210
Should suffice now for the duration.

08:52.230 --> 08:57.150
Let's give it a good 60s I want to be able to see it.

08:57.150 --> 09:00.480
In fact, I'm going to go two minutes 100 and 20s.

09:02.030 --> 09:04.550
And for thickness I'll put a five as well.

09:04.580 --> 09:07.670
Now with that we can test out how this works.

09:07.670 --> 09:11.840
Of course spawn projectiles is going to need to be blueprint callable.

09:11.840 --> 09:17.480
So before we compile and launch we're going to make it blueprint callable.

09:17.780 --> 09:21.680
And we can go ahead and see our debug arrow.

09:21.710 --> 09:22.880
We're starting small.

09:22.880 --> 09:25.250
Just a single debug arrow for now.

09:26.930 --> 09:28.100
And in the engine.

09:28.100 --> 09:34.660
We're going to open the Firebolt and find where we're spawning the projectile way down here at the end.

09:34.670 --> 09:41.000
And we're going to break this node and set it aside, because now we're going to try spawn projectiles

09:41.000 --> 09:44.480
with an S and we're going to hook in.

09:45.430 --> 09:49.210
A projectile target location and a socket tag.

09:49.240 --> 09:52.420
That's what we needed for spawn projectile.

09:52.420 --> 09:56.410
So we'll go ahead and we'll duplicate these nodes right here.

09:56.440 --> 09:58.150
We'll pass those in.

10:01.730 --> 10:05.900
We're not going to override the pitch for now, so we'll leave that as is.

10:05.930 --> 10:11.930
We're not using the homing target yet, so all we have now if we click.

10:12.730 --> 10:14.080
With shift.

10:14.110 --> 10:15.400
Then we'll see that arrow.

10:15.400 --> 10:19.060
And I'm going to go ahead and pause and eject.

10:19.060 --> 10:21.100
And I'll take a look at that arrow.

10:21.130 --> 10:23.590
The thickness is a little obnoxious.

10:23.620 --> 10:26.170
I think that that's a little bit too much.

10:26.170 --> 10:29.140
But at least we can see what we're working with here.

10:29.170 --> 10:29.740
Right.

10:29.740 --> 10:31.510
And we clicked on the ground over there.

10:31.510 --> 10:34.630
And we see that that arrow is pointing downward.

10:34.840 --> 10:37.030
That's good information to know.

10:37.150 --> 10:42.640
So for draw debug arrow for the thickness I'm just going to put this down to a smaller value.

10:42.670 --> 10:48.670
We'll try to and I also want to see if I have.

10:50.060 --> 10:52.700
A different color.

10:53.180 --> 10:55.640
I know I can custom make a color.

10:55.760 --> 11:01.340
I'm going to actually make the forward vector white to distinguish it from other vectors.

11:01.370 --> 11:04.880
Okay, so we saw that we're not overwriting the pitch.

11:04.880 --> 11:08.510
And that means our arrow is pointed downward a bit.

11:08.540 --> 11:12.290
I think I'll go ahead and override the pitch with a pitch of zero for now.

11:12.290 --> 11:15.140
But we can pass in a different value.

11:15.140 --> 11:17.240
But this line can be a single line.

11:17.240 --> 11:20.450
It's distracting me with how many lines it's taking up.

11:20.450 --> 11:24.830
So with that, we have our pitch override line here.

11:25.100 --> 11:25.520
Okay.

11:25.520 --> 11:33.320
So we have the forward vector, or at least the vector pointing in the direction from the socket towards

11:33.320 --> 11:34.370
the target.

11:34.550 --> 11:41.690
Now we're going to make an algorithm to determine a spread so that we can spawn multiple projectiles

11:41.690 --> 11:44.120
sort of fanned out or spread out.

11:44.150 --> 11:49.580
Which means we're going to need to know what kind of a spread we want.

11:49.580 --> 11:56.500
Do we want these spawned across a spread of 90 degrees, 45 degrees, what have you.

11:56.510 --> 11:59.990
So I'm going to make a protected section.

12:01.260 --> 12:04.590
And make a float called projectile spread.

12:05.160 --> 12:08.250
And I'll give it a default value of 90.

12:08.250 --> 12:12.150
But we'll make this a new property with edit defaults only.

12:12.150 --> 12:19.410
And we'll put these variables related to this in the category of Firebolt.

12:19.680 --> 12:20.050
Okay.

12:20.070 --> 12:22.020
So we have a projectile spread.

12:22.550 --> 12:25.430
We need to know how many projectiles to spawn.

12:25.630 --> 12:28.430
Now I'm going to make a const int 32.

12:28.460 --> 12:30.020
That's local called.

12:31.060 --> 12:32.680
NUM projectiles.

12:34.450 --> 12:42.700
And for Firebolt, this is going to depend on the ability level, but I want to cap this off.

12:42.700 --> 12:45.850
So I want a maximum number of projectiles.

12:45.850 --> 12:48.580
And this too could be a parameter.

12:48.580 --> 12:52.620
So I'm going to make another member variable.

12:52.630 --> 12:58.780
I use them as parameters, but I mean them not in the sense of input parameters to functions, but a

12:58.780 --> 13:03.340
parameter of the spawning projectile phenomenon.

13:03.340 --> 13:07.740
But the correct programming terminology is member variable, right?

13:07.750 --> 13:16.570
This is going to be max projectiles or max num projectiles, or max number of projectiles if you want

13:16.570 --> 13:18.130
to be very verbose.

13:18.160 --> 13:25.870
Max num projectiles can get five, but of course it's added defaults only, so num projectiles is going

13:25.870 --> 13:37.390
to be the minimum f math min between two values Max num projectiles and get ability level.

13:39.250 --> 13:41.030
Whichever is lowest.

13:41.050 --> 13:47.480
So if our ability level is one and Max num projectiles is five, we'll spawn one projectile.

13:47.500 --> 13:51.010
So whichever is lowest, that's how many we're going to spawn.

13:51.040 --> 13:59.470
Now if we're just spawning one projectile then we just need to spawn straight ahead.

14:00.160 --> 14:07.960
So we're going to have an if statement checking num projectiles if num projectiles is greater than one,

14:07.960 --> 14:11.320
because that's when we're going to do the spread algorithm.

14:11.350 --> 14:18.790
Otherwise we'll have an else case and say single projectile, because that's a simple case that doesn't

14:18.790 --> 14:22.510
really require any of this elaborate algorithm business.

14:22.660 --> 14:30.190
If NUM Projectiles is greater than one, that's going to affect what we do here because we're going

14:30.190 --> 14:34.030
to have a for loop, we're going to loop over the number of projectiles.

14:34.060 --> 14:38.380
We're going to say for in 32 I.

14:39.470 --> 14:41.090
We're going to start it at zero.

14:41.270 --> 14:46.250
We're going to go until I is no longer less than num projectiles.

14:50.030 --> 14:52.790
And we'll increment it by one each iteration.

14:53.180 --> 14:56.420
So what are we going to do in the for loop?

14:56.570 --> 15:02.030
Well, I'd like to do something similar to what we did in the Shaman Summon ability.

15:02.060 --> 15:07.550
I'd first like to take my forward vector that we're drawing down here.

15:07.550 --> 15:12.800
And of course for our debug we scaled that vector by 100.

15:13.580 --> 15:17.180
But really, all that matters is the direction.

15:17.240 --> 15:21.800
So we're going to have a const f vector called forward.

15:23.630 --> 15:25.790
That's going to be rotation vector.

15:27.990 --> 15:31.050
We're also going to have a spread.

15:31.050 --> 15:36.580
We know how far left and right to rotate our vector.

15:36.600 --> 15:39.720
Half of this 90 degrees here.

15:39.720 --> 15:46.920
So we're going to have a const f vector called left of spread.

15:47.820 --> 15:52.140
And this is going to be rotated just like in our summoned ability.

15:52.140 --> 15:53.220
Let's just look at that.

15:53.220 --> 15:58.260
In a summoned ability we took a left of spread right.

15:58.260 --> 16:05.550
And we took forward rotated it by negative spread divided by two rotating about the up vector.

16:05.550 --> 16:06.120
Right.

16:06.630 --> 16:16.230
So we can take forward and we can call rotate angle axis rotating by negative spread its projectile

16:16.230 --> 16:19.020
spread right divided by two.

16:19.710 --> 16:23.280
And we can rotate about the f vector up vector.

16:24.200 --> 16:31.380
And here in our for loop, we can do what we did or a summon ability by creating a direction, right?

16:31.400 --> 16:36.500
We start with left of spread and we rotate by delta spread times.

16:36.500 --> 16:38.000
I about the up vector.

16:38.000 --> 16:39.680
Well what's delta spread.

16:39.710 --> 16:43.790
That's going to be the spread in between each vector.

16:43.790 --> 16:44.360
Right.

16:44.360 --> 16:46.130
And an or a summon ability.

16:46.130 --> 16:52.160
That delta spread was calculated as the overall spread divided by the number of minions.

16:52.160 --> 16:55.310
In our case, it'll be the number of projectiles.

16:55.310 --> 16:57.950
But I'm going to show you what happens when we do that.

16:57.950 --> 17:02.300
I'm going to make a const float called Delta Spread.

17:02.750 --> 17:06.200
It's going to be our projectile spread.

17:06.910 --> 17:08.890
Divided by num projectiles.

17:08.890 --> 17:13.240
In other words, it has to be below this calculation.

17:13.840 --> 17:15.430
NUM projectiles.

17:17.380 --> 17:20.350
But I'll show you what happens when we do this.

17:20.710 --> 17:26.110
And to make it very clear what happens when we do this, I'm going to draw debug arrows for left of

17:26.110 --> 17:29.830
spread and right of spread, both in different colors.

17:29.830 --> 17:32.140
So I'm going to take this debug arrow.

17:32.830 --> 17:34.570
Line and copy it.

17:35.850 --> 17:42.570
And I'm going to draw another debug arrow starting from socket location but using left of spread.

17:42.600 --> 17:46.710
So it's going to be socket location plus left of spread times 100.

17:46.710 --> 17:49.160
And this one can be a different color.

17:49.170 --> 17:53.100
I'm going to make it gray and I'm going to draw another one.

17:53.820 --> 17:58.290
Only this will be socket location plus a right of spread.

17:58.290 --> 18:01.950
So I'm just going to this is just for debug purposes.

18:01.950 --> 18:03.870
Make a right of spread.

18:06.120 --> 18:12.790
And instead of rotating by negative, we're going to rotate by positive projectile spread by two.

18:12.810 --> 18:18.840
So now we should be able to see the forward vector left of spread and right of spread.

18:18.840 --> 18:20.390
Those are going to be gray.

18:20.400 --> 18:25.440
And let's just test this out and see those vectors.

18:25.440 --> 18:31.260
And we'll make sure to override the pitch with zero so that these will be parallel to the ground for

18:31.260 --> 18:32.820
ease of viewing.

18:33.900 --> 18:39.600
Oh, it looks like num projectiles hides the class member num projectiles.

18:39.630 --> 18:41.040
It looks like.

18:41.070 --> 18:46.590
Or a projectile spell has num projectiles, doesn't it?

18:46.620 --> 18:47.340
There it is.

18:47.340 --> 18:48.330
It's five.

18:48.360 --> 18:48.990
That's right.

18:48.990 --> 18:53.460
We put that in there so we can just use num projectiles.

18:53.490 --> 18:54.390
No problem.

18:54.390 --> 18:59.880
Here in aura Firebolt, we're just going to set num projectiles instead of declaring a new one.

18:59.880 --> 19:00.690
No problem.

19:00.690 --> 19:02.490
So that takes care of that.

19:02.580 --> 19:10.410
And before we go ahead and test out we just need to make sure we're using right of spread here for our

19:10.410 --> 19:12.360
second vector.

19:12.720 --> 19:14.310
So we have left of spread.

19:14.310 --> 19:16.500
We have right of spread.

19:16.710 --> 19:20.940
And for the arrow size and thickness they're looking a little bit thick.

19:20.940 --> 19:26.820
I'm going to go ahead and just set them back down to one for all of them.

19:26.970 --> 19:33.840
And our first debug arrow can be socket location plus forward.

19:37.980 --> 19:40.650
And with that, let's test this out.

19:42.450 --> 19:42.990
Okay.

19:42.990 --> 19:47.920
So I'm going to check pitch override so that those arrows are drawn flat.

19:48.000 --> 19:49.470
I'm going to hold shift.

19:49.650 --> 19:53.150
And we're going to draw these.

19:53.160 --> 19:57.630
And as you can see the middle most arrow is going forward.

19:57.630 --> 19:59.370
These are parallel to the ground.

19:59.370 --> 20:02.010
And here's our spread of 90 degrees.

20:02.040 --> 20:04.050
Left of spread is here.

20:04.050 --> 20:05.700
Right of spread is here.

20:05.850 --> 20:11.970
And between left of spread and forward is half of 90 which is 45.

20:12.000 --> 20:16.020
Between the forward and right of spread is again 45.

20:16.800 --> 20:23.400
So let's think of the implications of this on our delta because we have projectile spread divided by

20:23.400 --> 20:24.900
number of projectiles.

20:25.230 --> 20:29.610
Now our projectile spread is 90 and our number of projectiles is five.

20:29.640 --> 20:33.510
But imagine for a moment that num projectiles is two.

20:33.540 --> 20:40.620
If we do what we did in Awesome Inability, then we start at left of spread and every iteration we rotate

20:40.620 --> 20:42.750
by delta spread times I.

20:42.870 --> 20:47.270
The first iteration it would be zero, so that gives us left of spread.

20:47.280 --> 20:54.000
But then the next iteration gives us that vector rotated by delta spread times one, and so on.

20:54.000 --> 20:54.540
Right.

20:54.570 --> 20:59.070
What this does is and again imagine num projectiles is two.

20:59.100 --> 21:01.050
We start off at left of spread.

21:01.080 --> 21:02.850
That's when I equals one.

21:02.850 --> 21:09.150
And then we have one more iteration of the for loop where rotating by delta spread which is only half

21:09.150 --> 21:12.150
of 90 degrees because num projectiles is two.

21:12.180 --> 21:14.520
So we're rotating by 45.

21:14.940 --> 21:16.170
In other words.

21:18.510 --> 21:23.370
Our first vector is this one, and our second vector is this one.

21:23.490 --> 21:28.520
So we're launching two fireballs, one that way and one straight forward.

21:28.530 --> 21:34.620
We're not getting what we expected, which was one going off to the left and one going off to the right.

21:34.650 --> 21:38.610
So our delta spread shouldn't have been 45.

21:38.610 --> 21:39.960
It should have been 90.

21:39.990 --> 21:46.380
For this reason, we have to change delta spread instead of projectile spread divided by num projectiles,

21:46.410 --> 21:49.650
we have to divide by num projectiles minus one.

21:49.740 --> 21:51.150
Now this is very important.

21:51.150 --> 21:55.230
We have to have more than one num projectiles.

21:55.230 --> 21:59.490
Otherwise we're subtracting one from one and dividing by zero.

21:59.490 --> 22:05.460
So we have to place this inside the if check after checking to see if num projectiles is greater than

22:05.460 --> 22:05.730
one.

22:05.730 --> 22:10.410
Otherwise there's a chance of dividing by zero, which is not what we want.

22:10.500 --> 22:17.250
So now with this, let's see what happens if we do what we did in the sub.

22:17.250 --> 22:23.640
Inability, we make a direction vector taking our left of spread and rotating it by delta spread times

22:23.640 --> 22:24.360
I.

22:24.570 --> 22:26.780
So we're going to paste this here.

22:26.790 --> 22:28.950
We have a forward direction.

22:28.950 --> 22:33.570
And we can simply draw an arrow for each of these.

22:33.570 --> 22:41.580
So I'm going to get my yield draw debug arrow function and just paste it here.

22:41.850 --> 22:45.810
I'll go ahead and put each argument on its own line.

22:46.260 --> 22:48.840
And these arrows I'm going to draw red.

22:50.060 --> 22:51.500
And what am I drawing?

22:51.530 --> 22:59.450
I'm drawing at socket location for the line start and for the end socket location plus direction, and

22:59.450 --> 23:01.160
that can be multiplied.

23:01.160 --> 23:07.670
And I'm going to multiply it by a slightly shorter magnitude like so.

23:07.790 --> 23:14.810
And if we really want to see these separated from these three arrows down here, we can raise them.

23:14.810 --> 23:22.640
We can say socket location plus f vector zero, zero, 5 or 10.

23:24.840 --> 23:27.630
And we'll use socket location plus that.

23:27.930 --> 23:33.870
And if that's confusing as hell, I'm going to make a const f vector called start.

23:35.450 --> 23:38.060
And that's going to be socket location plus the up.

23:39.670 --> 23:41.290
Vector we created.

23:41.680 --> 23:48.460
And this will be start and this will be start plus direction scaled by 75.

23:48.730 --> 23:49.150
All right.

23:49.150 --> 23:50.530
So let's do this.

23:50.530 --> 23:54.340
And the only thing we need to keep in mind is we're doing this min now.

23:54.340 --> 23:56.470
So it's only going to be one.

23:56.500 --> 23:58.270
Our ability level is one.

23:58.270 --> 24:01.300
So we're going to have to save that for later.

24:01.300 --> 24:04.840
And for now just use what NUM Projectiles is set to.

24:04.840 --> 24:09.130
And we can set that of course in the blueprint and override it.

24:09.130 --> 24:10.960
But it's a value of five.

24:10.960 --> 24:13.450
So we'll just save this for later.

24:13.450 --> 24:16.480
Once we're done then we'll enforce that.

24:16.660 --> 24:20.650
But for now let's just see our pretty little red vector arrows.

24:22.530 --> 24:23.430
All right.

24:23.430 --> 24:26.780
So we see that our num projectiles is five.

24:26.790 --> 24:30.360
And if we launch all right we can see that spread.

24:30.360 --> 24:32.760
So I'm going to pause and I'm going to zoom on in.

24:32.760 --> 24:37.440
And we have the red vectors raised by ten as we expected.

24:37.440 --> 24:39.090
And now look at this.

24:39.090 --> 24:40.800
The spread is correct.

24:40.920 --> 24:45.480
And it doesn't matter how many we have as long as it's greater than one.

24:45.480 --> 24:48.690
If we set the NUM projectiles to two.

24:49.990 --> 24:52.030
And we do the same thing.

24:52.600 --> 24:55.020
Then we'll see what that spread looks like.

24:55.030 --> 24:56.620
Where it launching them.

24:56.620 --> 24:57.790
Like this.

24:58.280 --> 25:03.290
So what we need is logic that will take care of these cases separately.

25:03.320 --> 25:05.300
NUM projectiles is greater than one.

25:05.300 --> 25:08.960
We do this algorithm if it's not greater than one.

25:08.960 --> 25:11.030
In other words, it is one.

25:11.060 --> 25:15.290
Then our direction is actually going to be the forward vector.

25:15.290 --> 25:22.730
So we'll just represent that by drawing a debug arrow here starting at the socket location.

25:23.510 --> 25:31.970
And ending at socket location, plus the forward vector scaled by 75 or so.

25:31.970 --> 25:37.200
And we could even just do that start thing where we raise it by ten.

25:37.220 --> 25:39.980
I'm going to raise it actually only by five while we're working.

25:39.980 --> 25:41.780
So we have our start.

25:41.810 --> 25:47.270
We can just use that here instead of socket location like so.

25:47.270 --> 25:49.550
But you get the point.

25:49.580 --> 25:55.250
We had to subtract one from num projectiles before dividing and order.

25:55.250 --> 26:04.850
For this spread to be the exact number we need to accommodate for how many projectiles that we're launching.

26:05.710 --> 26:10.300
So again, here's what two projectiles looks like.

26:10.300 --> 26:17.530
And if I change the number of projectiles now to one, we should see it go straight forward right.

26:18.960 --> 26:22.620
And if we change it to three.

26:23.540 --> 26:31.430
We should see one in the middle and two spread out, and if we change it to seven, we'll still see

26:31.430 --> 26:32.120
one in the middle.

26:32.120 --> 26:36.900
There will always be one in the middle if we do a odd number right.

26:37.500 --> 26:40.590
But at least these are looking correct.

26:40.590 --> 26:46.770
And you'll notice with our shaman that the shaman spread seems rotated a little bit.

26:46.770 --> 26:52.740
And that's because we're not dividing by the number of minions minus one, we're just dividing by number

26:52.740 --> 26:53.550
of minions.

26:53.580 --> 26:56.820
And we saw that that gives us a shift to the left.

26:56.850 --> 26:59.010
We have to make that adjustment.

26:59.010 --> 27:02.910
So anyway, now we have the math that we need.

27:02.940 --> 27:08.880
We can make this any number like ten and we'll always have the correct spread.

27:14.340 --> 27:22.650
So this is a nice algorithm because now we can adjust the parameters and really control how this works.

27:22.650 --> 27:23.160
Right.

27:23.160 --> 27:26.280
Because it doesn't have to be 90 degrees.

27:26.310 --> 27:31.890
It could be 180, in which case the spread will range to.

27:32.550 --> 27:33.210
This.

27:33.210 --> 27:36.750
You know, we can have fireballs going straight out to the sides.

27:39.100 --> 27:47.680
And we could even make fireballs go in 360 degrees if we wanted to go all around the world, right?

27:49.000 --> 27:50.620
In all directions.

27:54.230 --> 27:57.110
So now we have a pretty nice system.

27:57.560 --> 28:02.450
I'm going to set num projectiles back to five and we'll have this behavior.

28:02.450 --> 28:05.330
But at least now we've got that math under control.

28:05.330 --> 28:08.720
And we have a pretty solid algorithm we could use here.

28:08.720 --> 28:16.120
And really this would be a pretty nice algorithm to just stick in our blueprint function library.

28:16.130 --> 28:24.710
If we ever need randomly spread rotators spread across a given angle with a given number of them, because

28:24.710 --> 28:29.060
that's always pretty useful for gameplay mechanics and things.

28:29.180 --> 28:35.090
All right, so now that we've got that math under control, it's time to actually start spawning multiple

28:35.090 --> 28:35.780
projectiles.

28:35.780 --> 28:37.220
And we'll handle that next.

28:37.520 --> 28:38.290
Great job.

28:38.300 --> 28:39.320
I'll see you soon.
