WEBVTT

00:07.140 --> 00:08.160
Welcome back.

00:08.600 --> 00:15.440
So we know that we can fire a projectile in the correct direction, but Aura doesn't face the correct

00:15.440 --> 00:16.280
direction.

00:16.280 --> 00:20.810
And to turn her towards the correct direction, I'd like to use motion warping.

00:20.840 --> 00:29.120
This is a nice, relatively new feature of Unreal Engine and it allows us to either move a character

00:29.120 --> 00:35.690
through space or orient a character towards a target simply in their montage.

00:35.720 --> 00:39.010
Now, to do this, we have to go into that montage.

00:39.020 --> 00:45.140
I have my assets character's aura animations folder in abilities.

00:45.140 --> 00:48.920
We have our Anim montage cast, Fire Bolt.

00:49.620 --> 00:54.950
And this uses the cast Firebolt animation, which I'm going to open up.

00:54.960 --> 01:02.040
And here in this animation assets, we can enable root motion and it looks like it's already checked

01:02.040 --> 01:03.540
in this particular asset.

01:03.540 --> 01:10.770
So if this is checked, then this is a root motion animation and can be used with motion warping.

01:11.100 --> 01:16.860
Now, if we're going to have motion warping, our character needs a motion warping component and this

01:16.860 --> 01:20.790
could be added from C plus plus, but I'm going to add it from Blueprint.

01:20.790 --> 01:23.880
I see no reason to add it from C plus plus.

01:23.880 --> 01:29.430
It's going to be just fine if we add it here in Blueprint and that's what I'm going to do.

01:29.430 --> 01:35.130
So I'm going to click add and search for motion warping and nothing pops up.

01:35.130 --> 01:37.950
And that's because we have to enable the plugin.

01:38.160 --> 01:46.470
So we go to edit plugins and search for motion warping and here is motion warping.

01:46.470 --> 01:52.920
It's still in beta and it warns you that it's in beta and it tells you not to use it in shipped projects.

01:52.920 --> 01:54.330
But I'm going to use it.

01:54.330 --> 01:57.150
I'm not worried, so I'm going to click yes.

01:57.270 --> 02:00.870
And now it wants me to restart, so I'm going to restart now.

02:01.990 --> 02:09.730
And now that we've restarted, I can open my asset editors that were open and we can now use motion

02:09.730 --> 02:10.180
warping.

02:10.180 --> 02:18.190
So I'm going to go back to Aura character, click add, search for motion warping and choose motion

02:18.190 --> 02:21.250
warping to get a motion warping component.

02:21.460 --> 02:25.720
Now we can use motion warping with our motion warping component.

02:25.870 --> 02:30.640
So to use motion warping with a given montage, we go to that montage.

02:31.330 --> 02:37.150
I'm going to open a m cast Firebolt and we add a notify section.

02:37.450 --> 02:40.870
So I'm going to start naming these notify tracks.

02:40.870 --> 02:50.650
I'm going to call one events and I'm going to add a new track and call this one motion warping and in

02:50.650 --> 02:51.670
motion warping.

02:51.670 --> 02:59.170
I'm going to right click and I want to motion warp from just about the beginning to just about right

02:59.170 --> 03:02.390
before we actually launch the Firebolt.

03:02.390 --> 03:05.480
So this will be a motion warping window.

03:05.480 --> 03:13.070
So I'm going to right click close to the beginning and add a notify state and choose motion warping

03:13.430 --> 03:19.280
and I can click on the end of it and hold shift to see the pose at this point.

03:19.280 --> 03:26.780
And I'm going to bring it on just before my montage event and I'm notify and with this motion warping

03:26.780 --> 03:30.320
state, we can configure this for motion warping.

03:30.560 --> 03:35.390
So for root motion modifier, we choose skew warp and expand this.

03:35.390 --> 03:37.640
And we need a warp target name.

03:37.910 --> 03:40.460
Now for our warp target name.

03:40.550 --> 03:43.250
It doesn't matter what we choose as long as we use this.

03:43.250 --> 03:50.600
When we set the warp target, I'm going to choose facing target because we're going to face the target

03:50.600 --> 03:56.060
and we're going to uncheck warp translation because we don't want to warp our position.

03:56.060 --> 03:58.220
We want to warp our rotation.

03:58.370 --> 04:03.980
So we're going to uncheck warp translation, but we're going to keep warp rotation checked.

04:03.980 --> 04:07.250
And for rotation type, we're going to choose facing.

04:07.250 --> 04:15.830
That way, our animation will rotate our root bone to face our target, which we've called Facing Target.

04:15.860 --> 04:17.270
Now, what is that target?

04:17.300 --> 04:24.080
Well, we have to set that, and I'd like to set that from our firebolt gameplay ability.

04:24.080 --> 04:31.970
And to do that, I'm going to create a function on or a character or at least an event that we can use

04:31.970 --> 04:33.770
to set the warp target.

04:33.770 --> 04:39.530
So I'm going to right click and create a custom event and this will just go on the character blueprint

04:39.530 --> 04:44.030
and this will be called set facing Target.

04:44.240 --> 04:47.210
Or we can even say set facing warp target.

04:47.210 --> 04:49.700
I'm just going to call it set facing target.

04:49.940 --> 04:53.660
And what we can do is take our motion warping component.

04:53.660 --> 04:59.690
And the function on this component that we're interested in is Add or update warp target.

04:59.690 --> 05:02.330
And we can do this with a location.

05:02.450 --> 05:10.580
So I'm going to use Add or update warp target from location, hook that up and this event can take a

05:10.580 --> 05:11.090
vector.

05:11.090 --> 05:20.330
So I'm going to select my event, Click plus choose Vector for the type and call this facing target

05:20.690 --> 05:28.100
and facing Target can go right in to target location, but we have to specify the warp target name.

05:28.100 --> 05:33.260
That's the name that we gave our warp target here in the montage.

05:33.260 --> 05:35.180
It's called Facing Target.

05:35.180 --> 05:38.930
So I'm just going to copy that and paste it on in here.

05:38.930 --> 05:41.510
So now we're updating Facing Target.

05:41.930 --> 05:48.320
So now while we're playing this montage, as long as we're in this motion warping window, if that facing

05:48.350 --> 05:53.660
target is set, then aura will rotate towards that direction.

05:53.810 --> 05:56.510
I'm going to move this just a little bit before.

05:56.510 --> 06:00.320
So we're facing that direction a little bit early here.

06:00.500 --> 06:07.460
And now we just need to set that warp target and we can do that from within the firebolt if we cast

06:07.460 --> 06:09.500
to BP or a character.

06:09.530 --> 06:13.430
Now this does make our firebolt dependent on aura character.

06:13.430 --> 06:20.750
So if we'd like to make this a little bit more flexible, we could create a function on the combat interface

06:20.750 --> 06:22.940
and cast to that instead.

06:22.940 --> 06:24.800
So we have that option.

06:24.800 --> 06:30.020
But what I'm going to do is for now, just cast to the Aura character.

06:30.020 --> 06:36.290
And I can do that because from within our ability here we can get our avatar actor.

06:36.290 --> 06:43.850
If we right click and type get Avatar actor, we can get it from the actor info and from there we can

06:43.850 --> 06:47.660
cast I'm going to cast to BP or a character.

06:50.190 --> 06:54.990
And from BP or a character, we can update that warp target.

06:55.020 --> 06:59.580
So just to see how this works, I'm going to take this and call.

06:59.580 --> 07:00.510
I forgot what it's called.

07:00.510 --> 07:02.430
It's set facing target.

07:02.460 --> 07:05.130
We're going to call set facing target.

07:08.160 --> 07:13.680
And we're going to pass in that projectile target location right here.

07:18.720 --> 07:19.350
Like so.

07:19.680 --> 07:22.100
And then we go on to play the montage.

07:22.110 --> 07:25.350
So we should see Aura face the correct direction.

07:25.350 --> 07:27.960
Now let's go ahead and test it out.

07:27.960 --> 07:32.430
I'm going to save all first and I'm going to hold shift and click.

07:32.430 --> 07:35.430
And there we see that character moved.

07:35.460 --> 07:37.440
It rotated to face the target.

07:37.440 --> 07:40.860
I'm going to try on the server and it worked.

07:41.550 --> 07:42.450
Perfect.

07:42.930 --> 07:45.660
So this works and it's great.

07:45.690 --> 07:49.800
It looks like set facing target has an issue here.

07:49.800 --> 07:55.050
I'm just going to right click refresh nodes and hook that in and that should fix it.

07:55.230 --> 07:58.530
And now things are working great.

07:58.530 --> 08:04.920
So as I said, now that our gameplay ability is dependent on a character, it's a little bit more coupled

08:04.950 --> 08:08.880
to it, or a character isn't dependent on the ability of course.

08:08.880 --> 08:10.770
So the dependencies are one way.

08:10.770 --> 08:18.450
So this isn't terrible, but if we wanted to use this for say, an enemy for example, well, we couldn't

08:18.450 --> 08:24.780
unless we cast to the enemy and then set the facing target on the enemy as well.

08:24.780 --> 08:30.480
So the way to make this a little bit more flexible is to use an interface instead.

08:30.840 --> 08:33.060
And that's going to be your quest.

08:33.790 --> 08:37.180
So for your quest, you're going to use the combat interface.

08:37.180 --> 08:43.090
And in the interface, you can go ahead and create a function to update the warp target.

08:43.120 --> 08:50.020
Now, we do have some things going on in Blueprint, and now we're adding a function in C plus plus.

08:50.020 --> 08:54.520
So you're going to need to figure out how to make the two work together.

08:54.520 --> 08:57.250
And for that, I leave it up to you.

08:57.490 --> 09:04.210
So pause the video and make this system more flexible by using the combat interface now.

09:07.760 --> 09:08.390
Okay.

09:08.390 --> 09:11.030
So we need to go back to the C plus plus side.

09:11.030 --> 09:17.960
I'm going to close the editor and we're interested in the combat interface now, so I'm going to close

09:17.960 --> 09:23.150
all tabs and open interaction actually in the public folder.

09:23.150 --> 09:31.250
Let's get interaction combat interface and we need a function to update the facing target.

09:31.370 --> 09:40.730
I'm going to call this void function update facing Target and it's going to take a const F vector by

09:40.730 --> 09:43.760
reference called Target.

09:44.510 --> 09:48.920
Now this needs to be something we can implement in Blueprint.

09:48.920 --> 09:56.450
So for that I'm going to give it a new function macro and we'll make this a blueprint implementable

09:56.450 --> 09:57.080
event.

09:57.080 --> 10:01.160
And for blueprint implementable events, we do not make them virtual.

10:01.160 --> 10:05.090
So now we can implement this in our Aura Character blueprint.

10:05.090 --> 10:07.190
Let's go ahead and run this.

10:09.050 --> 10:13.700
Well, open our asset editors and open a character.

10:13.700 --> 10:17.300
And we have our update facing Target.

10:18.180 --> 10:20.250
Blueprint implementable event.

10:20.280 --> 10:24.960
All we need to do is hook that in to add or update warp targets.

10:24.990 --> 10:27.180
Hooking up the target as well.

10:27.180 --> 10:30.990
And we don't need this set facing target event anymore.

10:31.260 --> 10:38.340
I'm going to delete it and we can go back to the firebolt and we don't need to cast to a character anymore.

10:38.370 --> 10:40.590
We are going to cast to the interface.

10:42.700 --> 10:43.780
Now, here's the thing.

10:43.780 --> 10:52.150
If I take get Avatar actor from actor info and I type cast to combat interface, it's not going to pop

10:52.150 --> 10:52.510
up.

10:52.510 --> 10:57.730
This might have been something that tripped you up, but we can fix that.

10:58.300 --> 11:05.020
By going back to our interface and here in our You interface, we can make it a blueprint type.

11:05.780 --> 11:10.100
So changing our new interface macro to have blueprint type.

11:10.100 --> 11:12.810
Now we should be able to use it in the blueprint.

11:12.830 --> 11:14.420
So let's go back.

11:14.630 --> 11:17.750
Compile, launch and see if we can do this now.

11:20.230 --> 11:20.800
Okay.

11:20.800 --> 11:22.510
Opening our assets.

11:22.540 --> 11:23.870
Let's go back.

11:23.890 --> 11:27.550
We know that this custom event no longer exists.

11:27.580 --> 11:35.440
We're going to go ahead and delete that and we'll get our Avatar actor cast to combat interface.

11:35.440 --> 11:40.000
And now we see that it shows up because it's a blueprint type.

11:40.180 --> 11:47.250
So we don't need or a character, we're going to use the interface from the interface as combat interface.

11:47.260 --> 11:49.090
We're going to call the function.

11:49.270 --> 11:57.160
And if we type update yet again, we're meeting another roadblock because yes, the function is blueprint

11:57.160 --> 11:58.180
implementable.

11:58.210 --> 12:01.000
We did not make it blueprint callable.

12:01.000 --> 12:08.680
So once again we go back to C plus plus and we add yet another macro specifier.

12:09.010 --> 12:11.200
It has to be blueprint callable.

12:11.200 --> 12:17.020
Now that it has that, let's go back into the editor and sometimes this is the process.

12:17.020 --> 12:23.570
You find that you hit roadblocks, you go back and fix one problem, you find the next problem.

12:23.570 --> 12:28.790
You go back and fix that and repeat the process until it works.

12:30.020 --> 12:33.800
All right, let's open our editors again.

12:33.800 --> 12:39.530
And this time, after we've cast to the combat interface, we can drag off.

12:39.920 --> 12:42.920
And now we have update facing target.

12:42.950 --> 12:46.640
We can pass in the target and continue.

12:47.060 --> 12:53.420
So there were a few things that we had to deal with when conquering this quest.

12:53.480 --> 13:00.350
We had to first figure out what to do about our function and how to replace that custom event, right?

13:00.380 --> 13:07.220
Now, you could have chosen a blueprint Native event, and you would basically implement it the same

13:07.220 --> 13:07.790
way.

13:07.820 --> 13:10.790
The only difference is it would be a blueprint native event.

13:10.790 --> 13:13.700
So you could have part of your functionality in C plus plus.

13:13.700 --> 13:18.140
I don't feel like I needed that, so I made it a blueprint implementable event.

13:18.170 --> 13:26.000
But I ran into the roadblock of not being able to cast to this interface because it wasn't a blueprint

13:26.030 --> 13:26.630
type.

13:26.630 --> 13:31.200
So we had to go back into the interface and add blueprint type.

13:31.200 --> 13:32.880
So that got me that far.

13:32.880 --> 13:38.910
But then I couldn't call update facing Target as it wasn't Blueprint callable, so I went back into

13:38.910 --> 13:41.850
the interface and gave it blueprint callable.

13:41.850 --> 13:43.860
So now we can see that blueprint.

13:43.860 --> 13:48.180
Implementable events that are blueprint callable can be in our interfaces.

13:48.210 --> 13:54.120
They can't be virtual, you can't mark it as virtual here if it's a blueprint implementable event,

13:54.120 --> 13:58.320
just like a blueprint, Native event can't be marked virtual either.

13:58.440 --> 14:03.180
So we got that working and let's see if it works in the editor.

14:03.180 --> 14:06.750
I'm going to hold shift and click and we rotate it.

14:06.780 --> 14:09.000
Let's try on the client shift.

14:09.000 --> 14:11.280
Click and we rotate.

14:11.280 --> 14:12.240
Perfect.

14:12.920 --> 14:19.590
So this is working and our firebolt is now no longer dependent on a character.

14:19.610 --> 14:26.450
That means we could potentially cast this spell from an enemy if the enemy implements update facing

14:26.480 --> 14:29.930
target and has that function to call.

14:30.080 --> 14:37.310
And we also can't cast this spell, or at least we can't get past this node if the cast to combat interface

14:37.310 --> 14:38.110
fails.

14:38.120 --> 14:43.620
So whoever's activating this ability very much has to implement combat interface.

14:43.640 --> 14:47.990
If we wanted it to be able to not implement it, we could simply hook up.

14:47.990 --> 14:52.100
Cast failed into play montage and wait like that.

14:52.100 --> 14:54.230
But I see no need for that.

14:54.380 --> 14:58.580
I'm okay with my ability requiring the combat interface.

14:58.700 --> 15:01.640
And now our ability is looking a lot better.

15:01.640 --> 15:04.790
It's by no means done, but it's looking better.

15:04.790 --> 15:07.300
And we have a couple of nodes here.

15:07.310 --> 15:11.510
We can remove those and things are looking great.

15:11.720 --> 15:16.560
Okay, so great job on the quest and I'll see you in the next video.
