WEBVTT

00:07.030 --> 00:08.110
Welcome back.

00:08.110 --> 00:14.410
So we have loot, but I'd like our loot to behave a little bit more dynamically when we spawn it.

00:14.410 --> 00:20.050
I'd like it to fly up and pop down, and then hover and rotate and all kinds of really juicy things

00:20.050 --> 00:22.900
that we can add for very little effort.

00:22.900 --> 00:29.530
So in this video, we're going to add a couple more capabilities to our aura effect actor that we can

00:29.530 --> 00:31.270
opt into or out of.

00:31.270 --> 00:37.120
Just keep in mind that this is going to involve the tick function, which means we'll now have a little

00:37.120 --> 00:38.980
bit less optimal code.

00:38.980 --> 00:43.600
Things that don't tick are less expensive than things that do, so keep that in mind.

00:43.600 --> 00:45.970
But of course this is just an option.

00:45.970 --> 00:55.540
Now, I'd like my aura effect actor to be able to rotate and bob up and down and just have tick functionality.

00:55.540 --> 00:59.740
And of course we can disable tick from actors in the blueprint pretty easily.

00:59.740 --> 01:03.340
So we don't have to opt into this for any actor.

01:03.340 --> 01:08.620
But if ticking is enabled, then I want to have some effects.

01:08.620 --> 01:13.150
So in my Aura Effect actor, I'm going to add a couple of things.

01:13.150 --> 01:17.860
I'm going to start by adding some options, some flags that we can turn on or off.

01:17.860 --> 01:23.080
I'm going to have a boolean called be rotates and by default set it to true.

01:24.350 --> 01:35.570
Give it a U property edit anywhere blueprint rewrite going to give full access to this category.

01:37.590 --> 01:39.180
Pick up movement.

01:40.440 --> 01:43.860
Now if we have rotation I want a rotation rate.

01:43.860 --> 01:53.430
So I'm going to make a float called rotation rate and set it to 45 by default and give it full exposure

01:53.430 --> 01:54.420
to blueprints.

01:55.110 --> 01:59.700
Now I'd also like to know if we'd like to bob up and down with sinusoidal movement.

01:59.700 --> 02:03.270
Sinusoidal meaning following a sine wave curve.

02:03.270 --> 02:10.080
And this will be a Boolean be sinusoidal movement.

02:10.740 --> 02:15.690
And I'm going to set this to false by default, because I don't want sinusoidal movement.

02:15.690 --> 02:23.250
In the beginning, when my potion is flying up and falling down, we'll enable this after a short period

02:23.250 --> 02:23.910
of time.

02:23.910 --> 02:26.850
So again, edit anywhere blueprint read right here.

02:27.660 --> 02:34.890
And then I'm going to have a function to start the sinusoidal movement called start sinusoidal movement.

02:37.870 --> 02:39.580
And this will be blueprint callable.

02:39.580 --> 02:42.460
So you function blueprint callable.

02:42.460 --> 02:46.300
And for sine waves there are a couple of parameters we can have.

02:46.540 --> 02:49.750
I can have a float called sine amplitude.

02:50.830 --> 02:53.320
I'm going to set that to one by default.

02:53.650 --> 02:56.860
And I can have a float called sine period.

02:57.400 --> 03:02.650
This can affect the rapidity or speed of bobbing up and down.

03:02.650 --> 03:06.310
And these two can also be added anywhere.

03:06.310 --> 03:06.700
Blueprint.

03:06.700 --> 03:07.480
Read write.

03:09.360 --> 03:18.000
Now, in order to have sinusoidal movement, I'm going to need an initial location that I want full

03:18.000 --> 03:19.350
access to in blueprint.

03:19.350 --> 03:27.750
So I'm going to make an F vector called initial location that I'm going to set right at the beginning

03:27.750 --> 03:29.610
when spawning this thing.

03:29.610 --> 03:34.050
But I'd also like to be able to reset it at any given point in time.

03:34.050 --> 03:37.470
So I'm going to make this exposed as well.

03:38.070 --> 03:45.180
And then finally I'm going to have a private non-exposed variable way down here at the bottom private.

03:46.380 --> 03:53.550
This will be a float called running time initialized to zero.

03:53.550 --> 03:58.920
So running time will keep track as we're updating our sinusoidal movement.

03:58.920 --> 04:01.410
So now we're going to need to tick.

04:01.410 --> 04:04.980
So I'm going to override the tick function in the public section.

04:04.980 --> 04:11.190
So virtualvoid tick takes a float called Delta time override.

04:12.090 --> 04:14.400
And we'll go ahead and generate this function definition.

04:14.400 --> 04:20.280
And we'll also generate the definition for start sinusoidal movement as well.

04:21.760 --> 04:27.400
And in begin play, the first thing I'll do is go ahead and.

04:28.090 --> 04:30.010
Store my initial location.

04:30.010 --> 04:30.640
Where is it?

04:30.640 --> 04:31.870
It's right.

04:32.840 --> 04:33.620
Here.

04:33.620 --> 04:36.530
I'm going to store that initial location right away.

04:36.530 --> 04:41.720
So we'll say initial location equals get actor location.

04:41.720 --> 04:44.270
And in tick we're going to update the time.

04:44.270 --> 04:45.290
The running time.

04:45.290 --> 04:49.340
We're going to say running time plus equals delta time.

04:49.730 --> 04:52.190
But running time could overflow.

04:52.190 --> 04:58.550
And because we're only using this for periodic sinusoidal movement, we're going to reset this to zero

04:58.550 --> 05:02.810
every time we've reached the period, which by the way, are period.

05:02.810 --> 05:09.770
A normal period for the sine wave is typically two pi.

05:09.830 --> 05:14.870
So we might as well just initialize this to about two pi just by default.

05:14.870 --> 05:21.710
6.28318 with a comment that says two times pi.

05:21.710 --> 05:23.720
And then we'll check.

05:23.720 --> 05:27.710
Every time running time exceeds this, we'll set it back to zero.

05:27.710 --> 05:36.980
We'll say if running time is greater than period or sine period.

05:39.580 --> 05:42.610
Running time equals zero.

05:44.110 --> 05:46.210
And in fact, we might as well.

05:47.640 --> 05:49.860
Give this a body there.

05:49.890 --> 05:54.720
Okay, so we're resetting it every time the period is reached.

05:54.720 --> 06:02.400
So now in tick we want to do our sinusoidal movement and start sinusoidal movement is going to set be

06:02.400 --> 06:08.820
sinusoidal movement to true and reset the initial location.

06:08.820 --> 06:13.140
So we're going to reset the initial location to the actor location.

06:13.140 --> 06:16.740
That way we now have the current location.

06:16.740 --> 06:21.180
So when we call start sinusoidal movement which we can call from blueprint.

06:21.180 --> 06:25.440
Then we reset the location and we start doing sinusoidal movement.

06:25.440 --> 06:30.570
And for that I'm going to have a movement function that we can call in tick.

06:30.570 --> 06:32.610
So I'm going to have a void function.

06:32.610 --> 06:37.650
This could even be a private internal function here void pickup.

06:38.100 --> 06:41.220
Or we'll say item movement.

06:42.400 --> 06:44.530
So we can generate this definition.

06:44.530 --> 06:45.550
I don't want it in line.

06:45.550 --> 06:51.970
So I'm going to copy it control X to cut it actually and move it up here next to tick.

06:52.780 --> 06:56.530
And we'll call this right here Item movement.

06:56.530 --> 06:58.900
Now we have a couple of booleans we can check right.

06:58.900 --> 07:00.580
We have B rotates.

07:00.580 --> 07:02.650
So we have B sinusoidal movement.

07:02.650 --> 07:04.270
So we can check those.

07:04.270 --> 07:06.220
So first I'll check b rotates.

07:06.220 --> 07:16.630
So if b rotates then I'm going to make a const f rotator called delta rotation.

07:18.220 --> 07:21.370
And initialize it with zero for pitch and roll.

07:21.370 --> 07:26.020
But for the yaw I'm going to use delta time, which means I need delta time.

07:26.020 --> 07:31.510
I'm going to go ahead and pass that into item movement so item movement can take a float.

07:33.480 --> 07:34.590
Delta time.

07:37.410 --> 07:43.740
So we'll get that passed in and we'll pass in Delta time from tick into item movement.

07:43.860 --> 07:48.840
And I'm going to take delta time and multiply by rotation rate.

07:48.840 --> 07:51.060
So we're scaling it by delta time.

07:51.060 --> 07:54.690
That's going to be for your pitch and roll are zero.

07:54.690 --> 08:01.770
And we can finally take our mesh or effect actor and we can rotate it.

08:01.770 --> 08:04.980
But of course our effect actor doesn't have a mesh does it.

08:04.980 --> 08:09.690
So really we can just set some proxy variable.

08:09.690 --> 08:14.880
And if we have a mesh in the blueprint, well we can use that, right?

08:14.880 --> 08:23.250
We can have a item location and item rotation that we can just set and then use in the blueprint.

08:23.250 --> 08:25.560
So I'm going to have those two.

08:25.590 --> 08:28.320
They'll be blueprint read only.

08:28.320 --> 08:38.820
So we're going to have an F vector called calculated location u property blueprint read only.

08:38.820 --> 08:47.280
And we'll have an F rotator calculated rotation with a u property.

08:48.370 --> 08:49.540
Blueprint read only.

08:50.920 --> 08:55.960
Now, what we can do with these is here in begin play.

08:55.960 --> 08:58.270
First of all, we can initialize these.

08:58.270 --> 09:04.420
And if we're going to initialize initial location and start sinusoidal movement we'll initialize it

09:04.420 --> 09:04.960
there as well.

09:04.960 --> 09:10.930
So what we'll do is we'll say calculated location equals initial location here.

09:10.930 --> 09:18.040
And calculated rotation equals get actor rotation.

09:19.130 --> 09:24.860
Like so now in item movement, delta rotation is calculated.

09:24.860 --> 09:29.960
And what we're going to do is just add this to our calculated rotation.

09:29.960 --> 09:32.420
So we're going to take calculated rotation.

09:35.030 --> 09:37.370
And we'll use you Kismet math library.

09:37.370 --> 09:41.780
Combine rotators or compose rotators is what I'm looking for.

09:41.780 --> 09:48.530
So we'll take first calculated rotation and we'll compose it with delta rotation.

09:48.530 --> 09:53.600
And that's the same effect as adding them together.

09:53.600 --> 10:00.590
So now our calculated rotation will be changing according to our rotation rate.

10:00.590 --> 10:02.540
Now for sinusoidal movement.

10:02.540 --> 10:10.610
If be sinusoidal movement then we have an initial location and we have our running time.

10:10.610 --> 10:14.690
So we need to calculate the sine of the running time.

10:14.690 --> 10:17.150
We can do a const float.

10:17.150 --> 10:18.950
We can call this sine.

10:18.950 --> 10:24.080
And we're going to take f math sine of running time.

10:24.710 --> 10:33.020
Now if we want to transform this we can transform it with the amplitude using sine amplitude here multiplying

10:33.020 --> 10:33.290
it.

10:33.290 --> 10:38.600
And if we want to affect the period we multiply running time by sine period.

10:40.740 --> 10:47.010
Now, mathematically, the period is actually two pi divided by this value.

10:47.040 --> 10:50.430
So this isn't actually the sign period.

10:50.430 --> 10:53.610
It's actually a sign period constant.

10:53.610 --> 10:57.240
So we can call this sign period constant.

11:00.020 --> 11:03.680
And let's just set it to one for now and I'll show you how this works.

11:03.680 --> 11:05.630
But we're going to say sign period.

11:05.630 --> 11:07.310
Constant equals one.

11:10.090 --> 11:18.610
So constant there and then we want to reset our running time every period and the sign period we can

11:18.610 --> 11:22.090
calculate here const float sign period.

11:22.090 --> 11:24.490
And that's going to be two times pi.

11:24.490 --> 11:33.490
We can use two times the constant pi that's built into the engine divided by sign period constant.

11:34.990 --> 11:42.490
So we really want to reset running time every sign period which is calculated by this formula.

11:42.490 --> 11:47.560
As long as we're using it properly here by multiplying by running time.

11:47.650 --> 11:52.330
So sign period is two pi divided by the sign constant.

11:52.330 --> 11:53.590
Sign constant is here.

11:53.590 --> 12:04.510
So now that we have the sign, we can set our calculated location by adding this value to the z.

12:04.510 --> 12:09.280
So we can say calculated location equals.

12:09.280 --> 12:11.320
And we can take initial location.

12:11.920 --> 12:20.920
And we can add the f vector with zero for x and y and z can be sign.

12:22.870 --> 12:26.320
So now we have calculated rotation and location.

12:26.320 --> 12:31.150
And we can set these on the mesh for whatever mesh we're using.

12:31.150 --> 12:34.840
And just like I have start sinusoidal movement.

12:35.430 --> 12:36.240
Where is it?

12:36.240 --> 12:37.620
Start sinusoidal movement.

12:37.620 --> 12:40.050
I'd also like a start rotation.

12:40.050 --> 12:46.710
And really just set B rotates to false by default because we're going to want the accurate rotation.

12:46.710 --> 12:48.990
We're setting the rotation when we spawn this thing.

12:48.990 --> 12:49.470
Right.

12:49.470 --> 12:53.430
So I'm going to have another blueprint callable function as well.

12:54.210 --> 12:56.730
And we'll call this start rotation.

12:59.630 --> 13:04.760
And start rotation is going to be similar to start sinusoidal movement.

13:04.760 --> 13:16.250
It's going to set be rotates to true and set our calculated rotation equal to get actor rotation.

13:16.250 --> 13:24.230
And while we're at it here we're going to set our calculated location as well to initial location.

13:27.900 --> 13:29.700
And start sinusoidal movement.

13:29.700 --> 13:30.900
So it's reset there.

13:30.930 --> 13:31.380
Okay.

13:31.380 --> 13:39.900
Let's compile and see how these work by calling start sinusoidal movement and start rotation and using

13:39.900 --> 13:46.620
those calculated values to set our location and rotation for these pickups.

13:46.620 --> 13:52.380
So I can go into my potions and open BP health potion for example.

13:52.980 --> 13:56.460
And we can go into event begin play.

13:58.110 --> 14:02.490
And we can call start sinusoidal movement.

14:03.110 --> 14:04.880
And we can call.

14:05.620 --> 14:07.390
Start rotation.

14:08.560 --> 14:14.050
And in tech, which by the way, in or effect actor tick is false.

14:14.050 --> 14:15.550
But we can enable it here.

14:15.550 --> 14:19.630
We can override it in the blueprint by searching for tick.

14:19.630 --> 14:23.890
Looks like start with tick enabled is already on overriding that.

14:23.890 --> 14:25.090
So here's event tick.

14:25.090 --> 14:30.010
I'm going to bring it over and I'm going to call set actor location.

14:37.160 --> 14:40.730
And I'm going to get calculated.

14:41.090 --> 14:42.200
Location.

14:46.380 --> 14:50.310
And I'm going to call set actor rotation.

14:53.090 --> 14:57.290
And get calculated rotation.

15:00.430 --> 15:05.740
So compiling that, I'm going to spawn some of these pickups.

15:08.150 --> 15:09.950
Looks like I need to load in.

15:09.950 --> 15:10.820
Of course.

15:13.430 --> 15:14.930
Through the load menu.

15:16.600 --> 15:18.400
Starting off with my spouse.

15:32.870 --> 15:35.750
Okay, so we got some rotation.

15:35.750 --> 15:38.780
We have some actors rotating and some not.

15:38.780 --> 15:43.310
Actually we only did this for the health potion, so that's expected.

15:43.310 --> 15:49.430
But I'm going to detach and come in close and see if we can see any sinusoidal movement.

15:49.430 --> 15:55.100
And sure enough we do have some slow bobbing behavior, but that amplitude is very low.

15:55.850 --> 15:59.870
Now, I don't want to have to go in and do this for all of my pickups.

15:59.870 --> 16:06.440
So an easy way to achieve this would be either to set the actor location and rotation in C plus plus,

16:06.440 --> 16:14.030
or to create a base pickup that all of my potions and crystals can inherit from.

16:14.030 --> 16:19.850
Either one is totally fine, but before doing that, I'm going to change my sine amplitude.

16:19.850 --> 16:25.730
I'm going to try a value of eight and see if that's a little bit more noticeable.

16:37.030 --> 16:39.490
So there's my potions.

16:39.490 --> 16:41.200
They're bobbing up and down.

16:41.200 --> 16:42.430
That's looking good.

16:42.430 --> 16:46.840
Let's actually increase that sign period as well.

16:47.930 --> 16:50.390
To four.

16:50.950 --> 16:53.710
Might be a little too fast, but we can try that.

17:09.710 --> 17:11.360
Okay, I like that better.

17:11.360 --> 17:12.050
Actually.

17:12.050 --> 17:14.600
I'm happy with these values.

17:14.600 --> 17:20.600
So I'm going to make a base pickup class that our pickups can inherit from.

17:20.600 --> 17:25.040
And they can still have their own overrides in their own blueprints.

17:25.040 --> 17:31.340
But I'm going to go to actor and just make a blueprint class here based on our effect actor.

17:31.460 --> 17:33.410
That's what these are all based on.

17:33.410 --> 17:37.430
And I'm going to call this VP pickup underscore base.

17:38.150 --> 17:43.520
And in pickup underscore base I'm going to take my event begin play.

17:43.520 --> 17:49.460
And we'll just for now start sinusoidal movement and rotation.

17:49.610 --> 17:52.520
And I don't need actor begin overlap.

17:52.520 --> 17:54.470
But I do want tick.

17:54.470 --> 17:56.480
And I'm going to take these.

17:58.260 --> 18:02.520
Control X to cut them and paste them here for tick.

18:03.120 --> 18:07.800
And I don't need those nodes in health potion anymore.

18:07.800 --> 18:13.290
But what I want now is to base my health potion on pickup base.

18:13.290 --> 18:17.280
But before we do, let's take a look at our class settings.

18:18.330 --> 18:21.300
And notice we have instant gameplay effect.

18:21.300 --> 18:22.470
Potion heal.

18:23.890 --> 18:24.850
Do not apply.

18:24.850 --> 18:25.150
None.

18:25.150 --> 18:25.870
Do not apply.

18:25.870 --> 18:26.200
None.

18:26.200 --> 18:27.070
Do not apply.

18:27.070 --> 18:28.480
Remove on and overlap.

18:28.480 --> 18:29.890
Act A level one.

18:30.520 --> 18:31.630
Easy to remember.

18:31.630 --> 18:37.450
Now if we go to class settings and change this to BP pickup base.

18:41.970 --> 18:46.350
Now, if we go back to class defaults, we can check to make sure those are the same.

18:46.470 --> 18:47.670
And they are.

18:47.700 --> 18:48.180
Great.

18:48.180 --> 18:54.450
Now if we go into pickup base we can set those sign properties to better values.

18:54.450 --> 18:59.280
I think sign amplitude was eight, sign period constant was four.

18:59.280 --> 19:04.500
And now anything that derives from pickup base can inherit that.

19:04.500 --> 19:08.760
And that's going to be our mana potion as well.

19:08.760 --> 19:09.900
Class settings.

19:09.900 --> 19:14.250
We're going to search for BP pickup base.

19:15.030 --> 19:20.940
We'll go to our crystals health crystal class settings.

19:20.940 --> 19:23.400
Set it to BP Pickup base.

19:24.110 --> 19:27.770
And mana crystal BP pickup base.

19:29.870 --> 19:30.320
Now.

19:30.320 --> 19:35.990
After saving, we should be able to see all of them bobbing up and down.

19:46.460 --> 19:52.700
And we have those nice bobbing sinusoidal movements and they look really nice and cool.

19:52.730 --> 19:53.270
All right.

19:53.270 --> 19:55.970
So that's going to wrap it up for this video.

19:55.970 --> 20:04.880
I noticed one issue though when moving when I clicked on something say outside of where I think I want

20:04.880 --> 20:06.860
to go, like on the rails or something.

20:06.860 --> 20:11.540
I think that auto running is never setting back to false.

20:11.540 --> 20:15.200
That's something that I need to fix in my player controller.

20:15.200 --> 20:23.660
And I think I remember in our player controller, in one of our recent changes we made right here in

20:23.660 --> 20:28.670
ability input tag pressed, we moved some things into is valid here.

20:28.670 --> 20:36.560
We moved setting our targeting status based on this actor and setting auto running to false when ability

20:36.560 --> 20:37.670
input tag is pressed.

20:37.670 --> 20:43.940
However, auto running should be false regardless of whether this actor is valid or not.

20:44.180 --> 20:50.930
So that's going to cause issues unless we go ahead and put this auto running outside the if check here,

20:50.930 --> 20:57.920
make sure we always set it to false as long as we're pressing the left mouse button here, we always

20:57.920 --> 20:58.940
want to set that to false.

20:58.940 --> 21:01.070
So that's going to fix that issue okay.

21:01.070 --> 21:03.830
So next time we compile that will be fixed.

21:03.830 --> 21:04.700
Excellent job.

21:04.700 --> 21:06.590
And I'll see you in the next video.
