WEBVTT

00:07.840 --> 00:08.780
Welcome back.

00:08.800 --> 00:14.170
In this video we're going to find out how to fix this pesky little problem with our firebolts.

00:14.440 --> 00:16.870
Sometimes they don't explode.

00:16.900 --> 00:23.950
Now what happens is, if we're launching a Firebolt at an enemy, and that enemy just happens to die

00:23.950 --> 00:30.220
before the Firebolt gets there, while the Firebolt still homes in on its homing target, which is now

00:30.220 --> 00:31.000
gone.

00:31.030 --> 00:32.680
Let me show you what I mean.

00:34.250 --> 00:35.090
There we go.

00:35.090 --> 00:39.620
So the enemy died and the Firebolt floats there.

00:39.620 --> 00:42.350
And after the enemy sort of perishes.

00:42.380 --> 00:43.250
Look at that.

00:43.250 --> 00:48.800
There's really no homing target for it to go to, and that's annoying.

00:48.890 --> 00:50.570
Now there's a fix to this.

00:50.600 --> 00:52.700
We can fix it in tick.

00:52.730 --> 00:54.230
Wait, wait, wait a minute.

00:54.260 --> 00:55.730
Did Stephen just say tick?

00:55.760 --> 00:57.290
Isn't that bad practice.

00:57.320 --> 00:59.450
Tick is always bad practice, right?

00:59.570 --> 01:06.990
Well, not if you can set the tick rate to a low value so an actor doesn't take very often.

01:07.010 --> 01:10.000
Let's go into ability, system or abilities.

01:10.010 --> 01:13.610
Fire Firebolt and get our Firebolt.

01:13.880 --> 01:20.800
Now an actor that ticks less often is a lot more performant.

01:20.810 --> 01:25.880
And if we have Firebolt self selected right here, we have a tick interval.

01:26.030 --> 01:29.630
Now if it's set to zero well that's going to be the maximum.

01:29.630 --> 01:38.450
And let's just see what that looks like by drawing a debug sphere at its location we're going to get

01:38.480 --> 01:39.770
actor location.

01:41.720 --> 01:47.810
And I'm going to promote this to a variable called location this frame.

01:51.200 --> 01:53.030
And I'm going to set that in tick.

01:53.030 --> 01:57.230
And I'm going to use that to draw a debug sphere with a radius of five.

01:57.260 --> 02:01.130
It's going to be white and its duration can be five seconds.

02:01.130 --> 02:04.760
So let's see how often that tick looks like.

02:06.990 --> 02:09.480
That's a whole lot of spheres, right?

02:09.810 --> 02:18.060
Now, if we set our tick rate, which is this tick interval here to 0.1, that's ten times per second.

02:18.090 --> 02:22.320
That's a lot less than 60 or 120.

02:22.680 --> 02:25.500
Modern computers these days it's 120.

02:25.500 --> 02:29.580
So ten times per second is not often at all.

02:29.610 --> 02:31.590
Let's check it out now.

02:33.560 --> 02:35.210
See, that's a lot less.

02:35.210 --> 02:40.340
And we could even put this down even more to say 0.2.

02:40.370 --> 02:43.460
That's five times per second.

02:44.320 --> 02:46.720
I mean, that's not very long now.

02:46.750 --> 02:52.960
My point is that we can use tech and we can see if that fireball has stopped moving.

02:53.140 --> 02:55.180
That's the approach I'd like to take.

02:55.180 --> 02:58.600
So I'm going to take that draw debug sphere, set it off to the side.

02:58.630 --> 03:00.970
We're going to set location this frame.

03:00.970 --> 03:08.260
But I'm also going to promote that get actor location to a variable and call this one.

03:08.290 --> 03:10.840
This will be the location last frame.

03:10.840 --> 03:13.720
So location last frame.

03:13.900 --> 03:18.190
And I'm going to set location last frame equal to.

03:19.350 --> 03:22.170
Location this frame before updating.

03:22.170 --> 03:24.690
Location this frame like that.

03:26.080 --> 03:31.420
And now we have this frame and last frame we can see the difference between them.

03:31.420 --> 03:36.190
So I'm going to take location this frame subtract location last frame.

03:36.190 --> 03:40.390
And we can get the vector length of this.

03:40.390 --> 03:44.050
And that will tell us how far apart these locations are.

03:44.290 --> 03:47.380
So if we get a vector length we can check it.

03:47.380 --> 03:50.980
And we can have a minimum we can have a threshold.

03:50.980 --> 03:57.250
So let's go ahead and make a variable called min distance per frame.

03:57.430 --> 03:59.680
This can be a float.

03:59.710 --> 04:01.060
We can compile.

04:01.060 --> 04:03.730
And we can set this to a low value like ten.

04:03.730 --> 04:12.130
And we can check if this vector length is less than or equal to min distance per frame.

04:12.130 --> 04:17.050
If that is the case, well, let's do a branch and decide what happens.

04:17.080 --> 04:21.040
What I'd like is for the projectile to go kaboom.

04:21.040 --> 04:28.840
So spawn sound at location at and let's just see what our impact sound is here.

04:30.400 --> 04:32.320
It's this sound effect right here.

04:32.320 --> 04:41.050
So I'm going to set that the location we have location this frame and then spawn system at location.

04:42.200 --> 04:46.700
And again, I want to see what impact effect we have here.

04:46.700 --> 04:47.660
It's this one.

04:47.660 --> 04:51.530
And actually we have to we're not using this one.

04:51.530 --> 04:57.110
So if we use this one we could change it up a little bit, change how it looks and then we'll know for

04:57.110 --> 05:00.500
sure if that is what is being spawned.

05:00.530 --> 05:03.800
So we'll do that at location this frame.

05:06.510 --> 05:07.470
Like so.

05:07.470 --> 05:09.780
And then we'll destroy the actor.

05:14.630 --> 05:19.340
Okay, now this explosion, I'm going to just change a bit.

05:19.370 --> 05:23.040
You can uncheck these emitters to change what it looks like.

05:23.060 --> 05:24.560
I'm just going to change it.

05:24.560 --> 05:26.680
So it just does one little thing.

05:26.690 --> 05:27.980
Perhaps just the ring.

05:29.860 --> 05:31.990
And maybe the sparks black.

05:33.530 --> 05:34.610
That's pretty different.

05:34.610 --> 05:35.870
So I'm going to save that.

05:35.870 --> 05:41.180
And now with our fix in place let's see what happens.

05:49.680 --> 05:52.920
And we definitely saw them explode.

05:55.270 --> 05:59.350
See, it hovered for a second and then it exploded, which actually looks pretty cool.

05:59.380 --> 05:59.610
See?

05:59.620 --> 06:03.730
Hover, explode and that little hover for a second.

06:03.760 --> 06:11.920
Of course, you can change the tick interval to a smaller value, but 0.2 is fine.

06:11.920 --> 06:13.870
It's only five times per frame.

06:13.870 --> 06:16.060
That is not that much at all.

06:16.060 --> 06:21.730
And of course all of this is something that could be moved into C plus plus as well.

06:21.740 --> 06:24.430
It's not going to be that much more performant.

06:24.880 --> 06:27.100
I'm just going to collapse it.

06:28.130 --> 06:34.520
To a function and call this make go kaboom.

06:36.530 --> 06:38.540
And we'll do that in event tech.

06:38.750 --> 06:42.560
We'll say make go kaboom if no move.

06:43.400 --> 06:45.980
Make go kaboom if no move.

06:46.530 --> 06:47.850
Perfectly descriptive.

06:47.850 --> 06:48.240
Right?

06:48.240 --> 06:49.230
Perfectly.

06:49.260 --> 06:50.040
All right.

06:50.040 --> 06:52.710
So that takes care of that issue.

06:52.710 --> 06:58.250
And of course, you don't have to play the weird little black tar looking explosion.

06:58.260 --> 07:00.390
You can play the regular explosion.

07:13.160 --> 07:14.120
Boom boom.

07:14.150 --> 07:14.930
Awesome.

07:14.930 --> 07:18.530
So yeah, we don't have to play that weird explosion.

07:18.530 --> 07:20.750
We can play our impact effect.

07:23.610 --> 07:27.270
So I'm just going to browse to that and use that system.

07:28.080 --> 07:33.120
And with that we have a very nice performant solution.

07:33.600 --> 07:36.150
I'll see you in the next video.
