WEBVTT

00:07.240 --> 00:08.330
Welcome back.

00:08.350 --> 00:13.270
So now that we're calculating the spread, we're ready to spawn some projectiles.

00:13.480 --> 00:20.070
But we're kind of repeating ourselves here as well as in or a summon ability here.

00:20.080 --> 00:26.290
In fact, we've discovered a shortcoming of this algorithm and improved it here in Aura Firebolt.

00:26.320 --> 00:33.430
And now that we have the formula perfected, it's probably a good idea to add a function for this in

00:33.430 --> 00:34.840
a function library.

00:35.140 --> 00:43.750
You see, needing some randomly spread rotators is actually kind of a common thing, and it would be

00:43.750 --> 00:47.110
useful to have just a function on deck for that.

00:47.110 --> 00:53.020
So I'd like to just put one of these into our ability system blueprint library.

00:54.220 --> 00:56.350
Aura ability system library.

00:57.360 --> 01:00.180
And this can be a static function.

01:01.150 --> 01:06.010
It can return a t array of f rotators.

01:08.300 --> 01:12.400
And we can get evenly spaced rotators about some spread.

01:12.410 --> 01:16.100
So we can call this evenly spaced rotators.

01:17.960 --> 01:24.480
And really all it needs is a forward vector and perhaps an axis of rotation.

01:24.500 --> 01:32.630
If we want this to be really versatile so we can pass in a const f vector by reference called forward

01:32.840 --> 01:39.170
and a const f vector by reference called axis.

01:39.560 --> 01:41.210
And we'll have our function.

01:41.210 --> 01:43.820
Now this gives us a t array of rotators.

01:43.820 --> 01:45.980
But what if we wanted them in vector form.

01:45.980 --> 01:47.660
We can make a vector version of it.

01:47.660 --> 01:54.500
So we can make a static function that returns a t array of f vectors.

01:55.280 --> 02:00.710
And we can call this evenly rotated vectors or something like that.

02:01.430 --> 02:04.340
Evenly rotated rotators is a funny name.

02:04.340 --> 02:09.920
I'm going to leave this at evenly spaced rotators, and we'll have evenly rotated vectors, and it'll

02:09.920 --> 02:11.210
take the same inputs.

02:12.890 --> 02:14.870
Now this could be a blueprint pure function.

02:14.870 --> 02:17.570
So I'll go ahead and give it a new function.

02:19.420 --> 02:21.760
And it's going to be.

02:22.060 --> 02:23.500
It could be in gameplay mechanics.

02:23.500 --> 02:24.370
That's fine.

02:25.470 --> 02:26.670
As the category.

02:26.670 --> 02:30.290
So both of these will be blueprint pure.

02:30.300 --> 02:33.810
I'm going to go ahead and generate the functions.

02:33.810 --> 02:37.320
And we already have the algorithm.

02:37.320 --> 02:40.830
We just need to get it from a Firebolt.

02:40.860 --> 02:44.670
So first thing we do is calculate our left of spread.

02:46.150 --> 02:50.620
So we're going to get that line and paste it here.

02:50.860 --> 02:54.160
But we need to know how much to spread.

02:54.160 --> 02:58.350
So these functions also need a spread angle right.

02:58.420 --> 03:00.640
So let's add that as well.

03:00.850 --> 03:03.940
We'll make a float called spread.

03:07.300 --> 03:10.390
That will be passed in to both of them.

03:13.590 --> 03:22.020
So we got left of spread and it's rotating our forward vector by half of spread about the up vector.

03:22.020 --> 03:23.760
But of course we're passing an axis.

03:23.760 --> 03:28.080
So if we wanted to we could pass in something other than the up vector.

03:28.080 --> 03:30.900
So that makes this a little bit more versatile.

03:31.110 --> 03:36.000
Now the next step after we have left of spread is we do a for loop right.

03:36.000 --> 03:37.980
So let's get this for loop here.

03:38.930 --> 03:41.000
Including that delta spread.

03:43.200 --> 03:46.920
So delta spread is going to take the overall spread.

03:48.440 --> 03:53.060
And divide by the number of rotators that we want.

03:53.210 --> 03:57.250
In other words, we need to pass in an integer here.

03:57.260 --> 03:59.990
So we're going to go ahead and do that.

04:00.140 --> 04:05.420
We'll have a int 32 called num rotators.

04:07.340 --> 04:12.350
But our vector version will take an int 32 called num vectors.

04:13.400 --> 04:15.290
So let's go ahead and add these.

04:18.420 --> 04:24.060
So we get numb rotators and this version gets an int 32 numb vectors.

04:25.420 --> 04:28.600
And I totally put this in the wrong place.

04:28.630 --> 04:33.960
This num rotators goes here and evenly spaced rotators.

04:33.970 --> 04:37.180
And then this num vector doesn't even go here.

04:37.210 --> 04:39.740
I'm going to cut it and put it where it belongs there.

04:39.760 --> 04:41.620
Now we should be fine.

04:42.010 --> 04:44.440
And we don't need num rotators there.

04:45.960 --> 04:50.700
Okay, so instead of numb projectiles we now have numb rotators.

04:50.700 --> 04:52.020
We're going to use that.

04:52.050 --> 04:56.820
Now we do need to make sure that numb rotators isn't one.

04:56.820 --> 04:59.760
If numb rotators is one, well that's easy.

05:00.900 --> 05:09.960
We can check if numb rotators is greater than one, then we'll do all this.

05:09.960 --> 05:15.630
So we'll put this stuff in there and we'll have the else case.

05:16.600 --> 05:17.410
Else.

05:17.970 --> 05:21.960
And in this case we have only one rotator to provide.

05:21.960 --> 05:27.300
And that's really just going to be the forward vector converted to a rotator.

05:27.480 --> 05:32.340
So we'll just have a T array of F rotators declared at the top.

05:32.340 --> 05:34.910
That will be for us to return.

05:34.920 --> 05:37.740
We'll call this rotators.

05:38.420 --> 05:42.170
Why is IntelliSense offering me this?

05:42.800 --> 05:45.210
Potential name rotators.

05:45.260 --> 05:48.830
It sounds like a variable name that Gollum would come up with.

05:49.550 --> 05:51.200
I'm going to call it rotators.

05:51.200 --> 06:00.110
So in the case rotators is going to be added to and we'll add forward into it forward rotation.

06:00.110 --> 06:05.510
That is now that's not working because I see up here we have rotators.

06:05.510 --> 06:09.050
That should be a T array of F rotator okay.

06:09.050 --> 06:15.260
So now if num rotators is greater than one then we have delta spread.

06:15.290 --> 06:19.130
We calculate that and then we loop.

06:19.130 --> 06:21.770
We loop over the number of rotators.

06:21.770 --> 06:23.840
So this will be num rotators.

06:23.840 --> 06:26.780
And we'll calculate it a direction.

06:26.900 --> 06:34.670
And that direction is going to be rotated by delta spread times I we don't need to draw a debug arrow

06:34.670 --> 06:36.590
and we don't need a start vector.

06:36.620 --> 06:41.750
All we need to do is take rotators and add to it.

06:41.780 --> 06:43.310
What are we adding?

06:43.550 --> 06:45.630
Direction rotation.

06:46.200 --> 06:49.130
And by the end of this we can return rotators.

06:49.720 --> 06:53.980
And looks like my typo is worse than I thought.

06:54.010 --> 06:56.980
I called this rotators.

06:57.250 --> 06:58.750
Oh, it's all the way back here.

06:58.780 --> 06:59.650
Oh, boy.

07:00.760 --> 07:02.410
All right, that fixes it.

07:02.830 --> 07:05.050
And now we have evenly spaced rotators.

07:05.050 --> 07:13.060
Now this is very much going to be similar for evenly spaced or evenly rotated vectors only we're going

07:13.060 --> 07:16.180
to make a t array of f vector called vectors.

07:16.840 --> 07:21.490
And we're still going to make a left of spread from the forward.

07:21.490 --> 07:30.010
And if num vectors is greater than one, then we create that delta spread using num vectors, looping

07:30.010 --> 07:31.630
over num vectors.

07:31.630 --> 07:38.440
And we take our direction, we rotate it, and then we take our vectors and add direction to it without

07:38.440 --> 07:39.940
converting to a rotator.

07:39.940 --> 07:43.300
So it's the same function without that extra step.

07:43.300 --> 07:46.420
And down here we're going to take vectors.

07:47.750 --> 07:49.160
And just add foreword.

07:49.160 --> 07:53.540
If we only have one and then we return vectors at the very end.

07:54.020 --> 07:58.460
Okay, so we now have two nice utility functions.

07:58.460 --> 08:03.950
And here in Aura Firebolt all we need to do is get those vectors.

08:03.950 --> 08:08.480
We have a number of rotated vectors we can get from this.

08:08.480 --> 08:14.900
So what I'd like to do is not even bother with left of spread and right of spread right.

08:14.900 --> 08:16.790
And all of this stuff.

08:16.790 --> 08:27.230
We can just make a single function call you or a ability system library evenly rotated vectors passing

08:27.230 --> 08:28.340
in forward.

08:28.850 --> 08:32.270
Our axis can be f vector up vector.

08:32.450 --> 08:42.890
Our spread is going to be projectile spread, and num vectors is going to be num projectiles.

08:44.240 --> 08:45.950
And now we have a tray.

08:48.350 --> 08:49.520
Of vectors.

08:50.450 --> 08:52.430
And we'll call this directions.

08:53.180 --> 08:55.520
And why did I write vectors.

08:56.330 --> 09:00.520
So now we have a 2D array of vectors for the directions.

09:00.530 --> 09:08.240
And it would be wise to just make sure that our function does what it's supposed to do by simply looping

09:08.240 --> 09:09.080
over directions.

09:09.080 --> 09:10.550
So we can say for.

09:11.630 --> 09:12.800
F vector.

09:13.530 --> 09:14.420
Ref.

09:15.210 --> 09:18.270
Direction and directions.

09:19.290 --> 09:21.570
And then we can just use this.

09:21.690 --> 09:24.540
Function call for draw debug arrow.

09:24.810 --> 09:30.300
And we're going to use the start location socket location.

09:30.510 --> 09:37.320
And the end location is going to be direction times 75 with all those parameters.

09:37.320 --> 09:39.720
And the rest of this can be commented out.

09:45.240 --> 09:48.740
And we can just make sure evenly rotated vectors works.

09:48.750 --> 09:56.880
And while we're at it, it would probably be a good idea to do the same thing with the rotator version.

09:56.880 --> 09:59.640
So I'm going to make a t array of F rotator.

10:00.330 --> 10:04.860
Didn't say rotators because it would make me type it as rotators.

10:04.860 --> 10:16.230
And I'm going to call this rotations and use you or ability system library evenly spaced rotators passing

10:16.230 --> 10:19.890
in forward f vector up.

10:24.230 --> 10:34.700
Up vector, projectile spread and numb projectiles and we'll just loop over rotations as well.

10:35.000 --> 10:38.300
So this will be for each rotator.

10:38.630 --> 10:41.990
We'll call it rotation I'll just call it root.

10:42.830 --> 10:47.330
We have a rotation up there looping through rotations.

10:47.330 --> 10:53.330
And then our socket location will be root dot vector times 75.

10:53.330 --> 10:56.600
Let's just run this and make sure both of these work.

10:56.600 --> 11:04.130
And actually before we test this I want to draw the rotation one in blue and slightly raised.

11:04.130 --> 11:15.290
So I'm going to make an f vector start socket location plus f vector 005.

11:16.610 --> 11:19.010
And we'll replace socket location with start.

11:19.040 --> 11:20.300
Now let's try.

11:21.830 --> 11:22.220
All right.

11:22.220 --> 11:23.720
We'll get the ability open.

11:23.720 --> 11:24.050
We'll see.

11:24.050 --> 11:26.000
We have five projectiles.

11:26.030 --> 11:28.340
Our spread is 90 degrees.

11:30.290 --> 11:31.280
There we go.

11:31.310 --> 11:34.790
Looks like both of our algorithms work just fine.

11:34.970 --> 11:36.620
There's the rotator version.

11:36.620 --> 11:38.290
There's the vector version.

11:38.300 --> 11:40.320
We have two to choose from.

11:40.340 --> 11:41.210
Perfect.

11:41.240 --> 11:46.220
All right, so now that we know those are working, we don't need all this debug stuff do we.

11:46.310 --> 11:50.600
So I'm going to go ahead and remove the debug stuff.

11:50.600 --> 11:52.040
All of this.

11:52.910 --> 11:55.960
I'm done with it I know my functions work.

11:55.970 --> 11:59.260
Now what I need to do is pick one of these.

11:59.270 --> 12:00.650
So I'm going to pick one of these.

12:00.650 --> 12:03.310
And the one I'm going to pick is rotations.

12:03.320 --> 12:06.350
So I have a t array of rotations.

12:06.350 --> 12:09.740
And that just goes back to our aura projectile spell.

12:09.740 --> 12:15.170
When we set a transform for the projectile we spawn we already have the location.

12:15.170 --> 12:17.420
We just need to set the rotation for it.

12:17.420 --> 12:21.530
And so for that simple reason I'm going to use rotations.

12:21.530 --> 12:26.270
I'm going to use a for loop and loop over rotations.

12:26.270 --> 12:32.960
We'll make a const f rotator reference for each iteration we'll call it rotation.

12:32.960 --> 12:37.010
We'll just call it root looping over rotations.

12:37.010 --> 12:40.130
And we want to spawn projectiles.

12:40.130 --> 12:42.590
So let's look at our projectile spell.

12:42.590 --> 12:50.450
We'll see that we have spawn transform made from socket location and rotation dot quaternion.

12:50.450 --> 12:54.170
Let's copy that and put it in our for loop only.

12:54.170 --> 12:57.080
Instead of rotation we're going to use root.

12:57.290 --> 13:02.690
And now that we have spawn transform we can go about spawning a projectile.

13:02.690 --> 13:11.660
And for now I'm just going to use the same code that we used in our projectile spell, namely just spawning

13:11.660 --> 13:15.200
a projectile of this type A or a projectile.

13:15.290 --> 13:17.660
I'll go ahead and include its type here.

13:21.550 --> 13:23.470
I'm going to steal it from.

13:23.470 --> 13:25.030
Or a projectile spell.

13:25.060 --> 13:26.050
There it is.

13:27.390 --> 13:33.530
It looks like I don't need gameplay tags there and back in aura Firebolts since I don't need Kismet

13:33.530 --> 13:35.030
System library.

13:35.180 --> 13:41.900
I'm going to replace it with Aura Projectile and I'm also going to collapse get description and next

13:41.900 --> 13:44.660
level description so I can see what I'm doing here.

13:44.660 --> 13:46.490
And we're spawning the actor.

13:46.490 --> 13:52.510
We're spawning it spawn transform setting damage effect params and finishing spawning.

13:52.520 --> 13:56.720
So with that we should see a number of fireballs come out.

13:57.200 --> 13:58.370
Let's give it a shot.

14:00.120 --> 14:03.920
All right, let's see if we get five projectiles.

14:03.930 --> 14:04.650
Boom!

14:04.650 --> 14:05.880
There they are.

14:05.910 --> 14:07.170
Really cool.

14:10.870 --> 14:16.360
Now I notice that the projectiles are spawning right away, and that's because I'm not hooking up my

14:16.360 --> 14:19.520
event received to spawn projectiles.

14:19.540 --> 14:24.430
So with that fixed now we'll get them spawned at the correct time.

14:25.880 --> 14:26.510
Pretty cool.

14:26.510 --> 14:31.280
And actually at this angle I can actually kill three of them.

14:31.280 --> 14:34.340
I can hit all three, which is pretty nice.

14:36.500 --> 14:37.490
Look at that.

14:38.620 --> 14:42.940
Okay, so now we have the ability to spawn five projectiles at once.

14:42.940 --> 14:49.150
And also with that pitch override, this is kind of cool because if I give it a pitch override of 45,

14:49.180 --> 14:54.550
then we'll spawn it 45 upward, 45 degrees upward.

14:55.550 --> 15:02.130
Now, obviously that looks definitely too high, but what if our projectiles had gravity?

15:02.150 --> 15:02.720
Right?

15:02.720 --> 15:03.980
Then it would be different.

15:03.980 --> 15:10.190
So in the next video, we're going to work on giving our projectiles gravity, as well as making them

15:10.190 --> 15:17.420
homing missiles so that our pitch override is going to look a little bit better when we set it to anything

15:17.450 --> 15:18.830
other than zero.

15:18.920 --> 15:21.500
With zero, they just go straight.

15:23.530 --> 15:24.340
Like so.

15:25.400 --> 15:25.910
Okay.

15:25.910 --> 15:26.940
Excellent job.

15:26.960 --> 15:28.670
I'll see you in the next video.
