WEBVTT

00:07.270 --> 00:07.870
All right.

00:07.870 --> 00:08.770
Welcome back.

00:08.770 --> 00:11.410
So we created a pretty cool algorithm.

00:11.410 --> 00:17.800
Whenever we're shocking something we're getting the five closest enemies to that thing.

00:17.800 --> 00:18.670
We're shocking.

00:18.700 --> 00:20.410
As long as we hit an enemy.

00:20.410 --> 00:20.950
Right.

00:20.950 --> 00:29.320
And here in electrocute, we are going to want to show some electric beams connected to those additional

00:29.320 --> 00:30.280
targets.

00:30.580 --> 00:34.120
So if I go over here and shock.

00:34.860 --> 00:38.700
I want to see a beam connected to the closest five targets.

00:39.410 --> 00:42.500
Now we had a debug sphere here.

00:42.500 --> 00:44.630
I'm just hitting control Z to undo that.

00:44.630 --> 00:49.250
So I can see as soon as I release my mouse button we get those five.

00:49.280 --> 00:53.390
Now that's because I put this in prepare to end ability.

00:53.390 --> 00:59.030
But really though, this actually belongs not in prepare to end ability.

00:59.030 --> 01:05.600
I'm going to control X to cut that and put this in spawn electric beam right after we've added the gameplay

01:05.600 --> 01:07.070
cue to the first actor.

01:07.070 --> 01:07.580
Right.

01:07.580 --> 01:10.580
And this stuff here, I don't need this anymore.

01:10.580 --> 01:17.270
I'm going to delete that and Ctrl V here we're going to store additional targets in spawn electric beam

01:17.270 --> 01:19.760
after we've added our first gameplay cue.

01:19.760 --> 01:22.160
And then we'll get these spheres right away.

01:25.060 --> 01:25.870
Excellent.

01:26.940 --> 01:31.710
So we get the first five or the closest five to the enemy.

01:33.760 --> 01:39.880
So how are we going to spawn beams from that enemy to those additional targets?

01:40.210 --> 01:42.100
Let's talk about that.

01:42.550 --> 01:45.510
Well, first I'm going to remove the debug sphere.

01:45.520 --> 01:54.280
And for each of our additional targets that we get, I'd like to make a function to handle adding that

01:54.280 --> 01:57.250
shock loop queue to those enemies.

01:57.310 --> 01:59.020
So I'm going to make a function.

01:59.980 --> 02:09.640
And I'm going to call this ad shock loop Q to additional target, and it's going to just take an actor.

02:09.670 --> 02:11.920
So we'll give it an input.

02:14.720 --> 02:17.810
And we'll call this target actor.

02:18.860 --> 02:22.760
Or we can call it actually additional target.

02:23.210 --> 02:24.980
And it's going to be an actor.

02:26.940 --> 02:29.130
So an actor object reference.

02:29.610 --> 02:30.000
Okay.

02:30.000 --> 02:31.200
What's it going to do?

02:31.530 --> 02:36.720
First thing I'm going to promote additional target to a local variable.

02:37.860 --> 02:40.650
We'll call it Target Actor.

02:42.150 --> 02:47.790
And I'm going to make gameplay parameters because we're going to add a gameplay queue to it.

02:47.820 --> 02:52.500
So we're going to do make gameplay queue parameters.

02:56.360 --> 02:58.490
And we're going to apply a gameplay cue.

02:58.490 --> 03:04.490
But before we go and do that, we need to keep track of all the actors we're applying a gameplay cue

03:04.490 --> 03:10.610
to, and we need to be able to identify which one is which and which one has which cue.

03:10.880 --> 03:18.170
So we need to associate these two together whenever we need to link an arbitrary number of pairs together.

03:18.440 --> 03:21.290
What's the data structure that comes to your mind?

03:21.650 --> 03:23.090
Just say it out loud.

03:23.510 --> 03:25.850
Well, what I think is a map.

03:26.060 --> 03:30.020
I'd like a map that maps one of these to the other.

03:30.050 --> 03:32.870
We could map the actor to its parameters.

03:32.870 --> 03:35.660
So I'm going to make a new variable.

03:35.660 --> 03:41.300
And this is not going to be a local variable, because we have to use this later on in the ability.

03:41.510 --> 03:47.540
So I'm going to add a variable and it's going to be called additional.

03:50.490 --> 03:53.010
Actors to params.

03:53.490 --> 03:56.520
Now I'll set its type to actor first.

04:00.300 --> 04:02.040
Actor object reference.

04:02.190 --> 04:06.860
But then I'm going to come over to its variable type and change it to a map.

04:06.870 --> 04:11.220
And if I change it to a map, I need to choose its key and value.

04:11.220 --> 04:13.590
By default it sets the value to integer.

04:13.590 --> 04:17.460
But I'm going to make this a gameplay cue.

04:18.000 --> 04:19.530
Parameters.

04:22.190 --> 04:29.660
So now we have a map of actors to gameplay parameters, and as soon as I make these params, I'm going

04:29.660 --> 04:34.820
to take my additional actors to q params and call add on it.

04:37.870 --> 04:43.510
And I'm going to add the target actor this right.

04:43.510 --> 04:47.620
So I made that a variable that's going to be the key.

04:47.860 --> 04:51.070
And our queue params is going to be the value.

04:52.500 --> 04:57.240
Now we need to set some of these Q params and the target itself.

04:57.240 --> 05:02.100
The target actor is going to be the source object.

05:02.400 --> 05:04.950
So not just mouse hit actor this time.

05:04.950 --> 05:07.020
Now we have target actor.

05:07.020 --> 05:10.830
And for the location it's going to be the target actor's location.

05:10.830 --> 05:12.840
So get actor location on that.

05:13.640 --> 05:15.740
We'll hook that into the location.

05:16.040 --> 05:18.860
And what about the target attach component?

05:18.860 --> 05:20.750
Well, before it was the weapon, right?

05:20.750 --> 05:22.970
It was the tip socket on the staff.

05:22.970 --> 05:29.000
But now we're connecting these electric beams from the mouse hit actor to each target.

05:29.000 --> 05:30.470
It's going to star out.

05:30.710 --> 05:35.420
So we're going to use the mouse hit actor for the attach target.

05:35.420 --> 05:39.860
And from the mouse hit actor we're just going to get its root component.

05:41.360 --> 05:43.070
That'll be its capsule.

05:43.070 --> 05:47.510
And that's going to be the target attach component.

05:48.460 --> 05:50.200
We can collapse that.

05:52.490 --> 05:53.480
Like so.

05:55.200 --> 06:03.780
And now we have a map keeping track of each of our additional targets and mapping it to the gameplay

06:04.050 --> 06:04.710
parameters.

06:04.710 --> 06:11.250
This will make it easy to remove those shock loop gameplay cue notifies later, and now all we need

06:11.250 --> 06:14.790
to do is add a gameplay cue on an actor.

06:14.790 --> 06:16.770
So I'm going to take that target actor.

06:17.750 --> 06:26.450
And call add gameplay cue on actor, and we'll hook this up and we'll specify the shock loop cue.

06:26.540 --> 06:30.350
And for the parameters that's going to be these params we just made.

06:32.380 --> 06:37.090
Now this is great because we're doing this for all of those additional targets.

06:37.090 --> 06:44.890
But now we also have a map mapping actor to params, which allows us to remove those params.

06:45.010 --> 06:48.190
So we can go to prepare to end ability here.

06:48.190 --> 06:56.680
And if that first target implements the combat interface, that is when we need to go through our map.

06:56.830 --> 07:02.440
If it does not, then we didn't hit anything except for maybe a wall or the floor.

07:02.440 --> 07:03.850
So that's this case.

07:03.850 --> 07:07.360
We don't care about that, but in this case we do.

07:07.360 --> 07:11.380
And we're going to need to loop over our map.

07:11.880 --> 07:15.390
Now, the thing about maps and blueprints is we can't loop over them.

07:15.390 --> 07:20.090
We can't say for each like we can do in C plus plus.

07:20.100 --> 07:25.880
Unfortunately, blueprint still has a few limitations in that regard.

07:25.890 --> 07:32.400
So for that reason, we can't really loop through the map, but we do have an array.

07:32.400 --> 07:39.690
If we go back to spawn electric beam, when we store additional targets here, we can promote that to

07:39.690 --> 07:41.190
an array variable.

07:41.190 --> 07:46.410
We can drag off promote a variable, and we have our additional targets.

07:47.430 --> 07:49.740
We'll just call it additional targets there.

07:50.230 --> 07:51.910
And we can store that.

07:52.580 --> 07:53.690
No problem.

07:53.930 --> 08:00.740
And after we loop through each of the actors in additional targets and we call this function, we just

08:00.740 --> 08:05.180
made add shock loop to additional target, we'll call it.

08:05.270 --> 08:10.880
But since we stored additional targets, now we can loop through that.

08:10.880 --> 08:12.980
So we can get additional targets.

08:12.980 --> 08:15.560
And we can do a for each loop.

08:18.510 --> 08:21.330
We don't need to try to loop over the map.

08:21.330 --> 08:22.460
We can't do that.

08:22.500 --> 08:30.720
But now we can remove the shock loop Q so we can take the additional target.

08:30.930 --> 08:33.300
We can then get our map.

08:34.200 --> 08:37.710
And we can call on the map find.

08:39.110 --> 08:41.090
And we can pass in that target.

08:41.450 --> 08:43.300
So that's the array element.

08:43.310 --> 08:50.510
So we can try to find this key value pair searching for the key that is this actor.

08:51.390 --> 08:53.190
And if we find it.

08:53.190 --> 08:55.500
So we'll have the branch on the loop body.

08:55.770 --> 08:59.480
We'll remove a gameplay cue from that actor.

08:59.490 --> 09:05.280
So we'll take that array element and call remove gameplay cue on actor.

09:06.350 --> 09:07.760
Hook that into true.

09:08.910 --> 09:17.760
And we'll use the shock loop gameplay cue, and the parameters will be the parameters we found in our

09:17.760 --> 09:19.290
find note here.

09:19.950 --> 09:26.820
Now this could be a function, and if I collapse it to a function, I think I'm going to get two inputs

09:26.820 --> 09:27.720
for that actor.

09:27.720 --> 09:28.590
Let's see.

09:28.830 --> 09:30.960
Yeah, we got two actors.

09:31.780 --> 09:34.480
But those are both the same one, aren't they?

09:34.960 --> 09:36.610
It's the array element.

09:36.880 --> 09:44.620
So I'm going to hold control and click and drag off of this and add a root node and hook that in.

09:44.620 --> 09:49.390
And that way I can collapse this to a function with only one input.

09:51.290 --> 09:58.940
And this will be called remove shock loop queue from additional target.

10:00.260 --> 10:03.590
And this function is going to look a little messy.

10:03.620 --> 10:12.920
What we can do to clean it up is take the input pin and we can call it additional target.

10:14.090 --> 10:17.420
And we can promote it to a local variable.

10:19.120 --> 10:21.490
And then use the local variable.

10:23.500 --> 10:28.270
We're going to call this new local variable target.

10:30.900 --> 10:32.790
And we'll use that here.

10:37.910 --> 10:38.910
Hook that up.

10:38.930 --> 10:43.310
Get rid of that reroute node and we'll hook up target here.

10:45.990 --> 10:47.970
Just to try to make this pretty.

10:50.150 --> 10:54.180
So additional target promoted to local variable.

10:54.200 --> 10:57.310
We take additional actors to q params.

10:57.320 --> 11:05.690
Try to find that target in it, and if we find it, we remove gameplay q with shock loop and these parameters

11:05.690 --> 11:06.980
from the target.

11:07.430 --> 11:12.680
So here in prepare to end, we loop through additional targets and call that.

11:13.420 --> 11:21.400
Now the last thing to do is use our ad hoc loop queue to additional target here in spawn electric beam

11:21.400 --> 11:24.150
as we're looping over our additional targets.

11:24.160 --> 11:31.060
So we're going to call Add Shock loop to additional target passing in the array element in for the additional

11:31.060 --> 11:31.720
target.

11:33.270 --> 11:34.650
Now with that.

11:35.450 --> 11:38.300
We're adding a gameplay cue.

11:38.570 --> 11:46.010
We're storing its cue parameters in a map, mapping that actor to the cue parameters, and then in prepare

11:46.010 --> 11:52.200
to End, we're looping over additional targets and removing those cue parameters from that target.

11:52.220 --> 11:53.510
Let's see how this works.

11:56.040 --> 11:57.750
Look at that.

11:59.200 --> 11:59.470
Oh.

11:59.470 --> 12:00.760
That's beautiful.

12:05.320 --> 12:09.460
And the cool thing is, if one of these is in the way, we'll hit that one.

12:11.660 --> 12:12.290
See.

12:22.630 --> 12:24.350
Some nice algorithm work there.

12:24.370 --> 12:26.530
Now check this out.

12:26.530 --> 12:27.670
I found a bug.

12:27.910 --> 12:31.330
I hit the floor over here, and my sphere.

12:31.330 --> 12:33.490
Trace, hit this goblin here.

12:33.970 --> 12:43.540
Now, because of that, my initial trace actually hit something that's not a combat interface.

12:43.540 --> 12:50.110
But my sphere trace ended up hitting this goblin here, and we ended up doing our algorithm.

12:50.110 --> 12:54.940
And because of that, we never removed those gameplay cues.

12:55.180 --> 12:58.210
So that's something we need to take into account.

12:58.390 --> 13:00.620
So how does that happen?

13:00.640 --> 13:03.310
First of all, we'll go to spawn electric beam.

13:05.290 --> 13:08.020
And we trace our first target.

13:08.020 --> 13:12.090
And by the time we get to does implement interface.

13:12.100 --> 13:18.500
This is where we know at this point if mouse hit actor is an enemy or not.

13:18.520 --> 13:19.840
But here's the thing.

13:19.840 --> 13:27.460
By this point, we should know if there was a goblin in the way because we need to update that goblin

13:27.490 --> 13:30.700
to the new mouse hit actor.

13:30.730 --> 13:32.590
We have to do that first.

13:33.130 --> 13:38.410
Now we should be updating mouse hit actor here if our sphere trace hit it.

13:38.440 --> 13:40.840
So let's just see.

13:45.780 --> 13:47.130
If we miss.

14:01.390 --> 14:06.730
Okay, so I know by this point if I hit the floor that this check.

14:07.710 --> 14:10.620
Is going to return a false.

14:10.980 --> 14:13.500
The floor does not implement the interface, right?

14:13.500 --> 14:19.920
So if we hit false and we set our target to the self the avatar actor.

14:20.010 --> 14:22.800
We add the looping queue to that.

14:22.830 --> 14:26.100
We don't want to store additional targets in that case.

14:26.100 --> 14:29.610
So here we should actually check that boolean.

14:29.610 --> 14:30.450
Right.

14:30.480 --> 14:34.650
We should have a branch that checks this boolean.

14:34.650 --> 14:36.660
First target implements interface.

14:36.690 --> 14:41.010
If it doesn't we don't need to do this whole additional targets thing.

14:41.280 --> 14:43.740
So let's give that a try.

14:45.860 --> 14:46.460
Yeah.

14:46.460 --> 14:50.690
So if we didn't check that, let's just hook false in there too.

14:50.720 --> 14:53.870
Then we're checking within an 850.

14:54.640 --> 14:56.290
Unit radius, right?

15:01.020 --> 15:08.560
But if we check first, if the first target implements the combat interface, then that won't happen.

15:08.580 --> 15:11.640
It's only if we actually hit an enemy.

15:15.800 --> 15:16.700
Awesome.

15:20.820 --> 15:23.160
Wow, this looks really cool, doesn't it?

15:27.160 --> 15:32.380
And if we tie the number of beams to the ability level, then that gives us an incentive to level it

15:32.380 --> 15:32.950
up.

15:33.250 --> 15:34.240
Awesome.

15:34.240 --> 15:37.810
So now we have the visual side of things looking pretty good.

15:37.840 --> 15:40.000
We can also check on.

15:40.610 --> 15:43.010
The client to make sure things work there.

15:44.450 --> 15:45.890
So on the client.

15:48.930 --> 15:51.870
Looks like things are working and consistent.

15:53.020 --> 15:54.370
And on the server.

15:56.350 --> 15:57.460
Things look good.

15:59.470 --> 16:00.400
Perfect.

16:02.360 --> 16:03.080
All right.

16:03.080 --> 16:04.270
Excellent job.

16:04.280 --> 16:10.340
This ability is starting to look a lot better, and we now need to start thinking about damage.

16:10.340 --> 16:12.470
We'll do that in the videos to come.

16:12.770 --> 16:13.920
Excellent job.

16:13.940 --> 16:16.250
I'll see you in the next video.
