Welcome back.
So we know that we can fire a projectile in the correct direction, but Aura doesn't face the correct
direction.
And to turn her towards the correct direction, I'd like to use motion warping.
This is a nice, relatively new feature of Unreal Engine and it allows us to either move a character
through space or orient a character towards a target simply in their montage.
Now, to do this, we have to go into that montage.
I have my assets character's aura animations folder in abilities.
We have our Anim montage cast, Fire Bolt.
And this uses the cast Firebolt animation, which I'm going to open up.
And here in this animation assets, we can enable root motion and it looks like it's already checked
in this particular asset.
So if this is checked, then this is a root motion animation and can be used with motion warping.
Now, if we're going to have motion warping, our character needs a motion warping component and this
could be added from C plus plus, but I'm going to add it from Blueprint.
I see no reason to add it from C plus plus.
It's going to be just fine if we add it here in Blueprint and that's what I'm going to do.
So I'm going to click add and search for motion warping and nothing pops up.
And that's because we have to enable the plugin.
So we go to edit plugins and search for motion warping and here is motion warping.
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.
But I'm going to use it.
I'm not worried, so I'm going to click yes.
And now it wants me to restart, so I'm going to restart now.
And now that we've restarted, I can open my asset editors that were open and we can now use motion
warping.
So I'm going to go back to Aura character, click add, search for motion warping and choose motion
warping to get a motion warping component.
Now we can use motion warping with our motion warping component.
So to use motion warping with a given montage, we go to that montage.
I'm going to open a m cast Firebolt and we add a notify section.
So I'm going to start naming these notify tracks.
I'm going to call one events and I'm going to add a new track and call this one motion warping and in
motion warping.
I'm going to right click and I want to motion warp from just about the beginning to just about right
before we actually launch the Firebolt.
So this will be a motion warping window.
So I'm going to right click close to the beginning and add a notify state and choose motion warping
and I can click on the end of it and hold shift to see the pose at this point.
And I'm going to bring it on just before my montage event and I'm notify and with this motion warping
state, we can configure this for motion warping.
So for root motion modifier, we choose skew warp and expand this.
And we need a warp target name.
Now for our warp target name.
It doesn't matter what we choose as long as we use this.
When we set the warp target, I'm going to choose facing target because we're going to face the target
and we're going to uncheck warp translation because we don't want to warp our position.
We want to warp our rotation.
So we're going to uncheck warp translation, but we're going to keep warp rotation checked.
And for rotation type, we're going to choose facing.
That way, our animation will rotate our root bone to face our target, which we've called Facing Target.
Now, what is that target?
Well, we have to set that, and I'd like to set that from our firebolt gameplay ability.
And to do that, I'm going to create a function on or a character or at least an event that we can use
to set the warp target.
So I'm going to right click and create a custom event and this will just go on the character blueprint
and this will be called set facing Target.
Or we can even say set facing warp target.
I'm just going to call it set facing target.
And what we can do is take our motion warping component.
And the function on this component that we're interested in is Add or update warp target.
And we can do this with a location.
So I'm going to use Add or update warp target from location, hook that up and this event can take a
vector.
So I'm going to select my event, Click plus choose Vector for the type and call this facing target
and facing Target can go right in to target location, but we have to specify the warp target name.
That's the name that we gave our warp target here in the montage.
It's called Facing Target.
So I'm just going to copy that and paste it on in here.
So now we're updating Facing Target.
So now while we're playing this montage, as long as we're in this motion warping window, if that facing
target is set, then aura will rotate towards that direction.
I'm going to move this just a little bit before.
So we're facing that direction a little bit early here.
And now we just need to set that warp target and we can do that from within the firebolt if we cast
to BP or a character.
Now this does make our firebolt dependent on aura character.
So if we'd like to make this a little bit more flexible, we could create a function on the combat interface
and cast to that instead.
So we have that option.
But what I'm going to do is for now, just cast to the Aura character.
And I can do that because from within our ability here we can get our avatar actor.
If we right click and type get Avatar actor, we can get it from the actor info and from there we can
cast I'm going to cast to BP or a character.
And from BP or a character, we can update that warp target.
So just to see how this works, I'm going to take this and call.
I forgot what it's called.
It's set facing target.
We're going to call set facing target.
And we're going to pass in that projectile target location right here.
Like so.
And then we go on to play the montage.
So we should see Aura face the correct direction.
Now let's go ahead and test it out.
I'm going to save all first and I'm going to hold shift and click.
And there we see that character moved.
It rotated to face the target.
I'm going to try on the server and it worked.
Perfect.
So this works and it's great.
It looks like set facing target has an issue here.
I'm just going to right click refresh nodes and hook that in and that should fix it.
And now things are working great.
So as I said, now that our gameplay ability is dependent on a character, it's a little bit more coupled
to it, or a character isn't dependent on the ability of course.
So the dependencies are one way.
So this isn't terrible, but if we wanted to use this for say, an enemy for example, well, we couldn't
unless we cast to the enemy and then set the facing target on the enemy as well.
So the way to make this a little bit more flexible is to use an interface instead.
And that's going to be your quest.
So for your quest, you're going to use the combat interface.
And in the interface, you can go ahead and create a function to update the warp target.
Now, we do have some things going on in Blueprint, and now we're adding a function in C plus plus.
So you're going to need to figure out how to make the two work together.
And for that, I leave it up to you.
So pause the video and make this system more flexible by using the combat interface now.
Okay.
So we need to go back to the C plus plus side.
I'm going to close the editor and we're interested in the combat interface now, so I'm going to close
all tabs and open interaction actually in the public folder.
Let's get interaction combat interface and we need a function to update the facing target.
I'm going to call this void function update facing Target and it's going to take a const F vector by
reference called Target.
Now this needs to be something we can implement in Blueprint.
So for that I'm going to give it a new function macro and we'll make this a blueprint implementable
event.
And for blueprint implementable events, we do not make them virtual.
So now we can implement this in our Aura Character blueprint.
Let's go ahead and run this.
Well, open our asset editors and open a character.
And we have our update facing Target.
Blueprint implementable event.
All we need to do is hook that in to add or update warp targets.
Hooking up the target as well.
And we don't need this set facing target event anymore.
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.
We are going to cast to the interface.
Now, here's the thing.
If I take get Avatar actor from actor info and I type cast to combat interface, it's not going to pop
up.
This might have been something that tripped you up, but we can fix that.
By going back to our interface and here in our You interface, we can make it a blueprint type.
So changing our new interface macro to have blueprint type.
Now we should be able to use it in the blueprint.
So let's go back.
Compile, launch and see if we can do this now.
Okay.
Opening our assets.
Let's go back.
We know that this custom event no longer exists.
We're going to go ahead and delete that and we'll get our Avatar actor cast to combat interface.
And now we see that it shows up because it's a blueprint type.
So we don't need or a character, we're going to use the interface from the interface as combat interface.
We're going to call the function.
And if we type update yet again, we're meeting another roadblock because yes, the function is blueprint
implementable.
We did not make it blueprint callable.
So once again we go back to C plus plus and we add yet another macro specifier.
It has to be blueprint callable.
Now that it has that, let's go back into the editor and sometimes this is the process.
You find that you hit roadblocks, you go back and fix one problem, you find the next problem.
You go back and fix that and repeat the process until it works.
All right, let's open our editors again.
And this time, after we've cast to the combat interface, we can drag off.
And now we have update facing target.
We can pass in the target and continue.
So there were a few things that we had to deal with when conquering this quest.
We had to first figure out what to do about our function and how to replace that custom event, right?
Now, you could have chosen a blueprint Native event, and you would basically implement it the same
way.
The only difference is it would be a blueprint native event.
So you could have part of your functionality in C plus plus.
I don't feel like I needed that, so I made it a blueprint implementable event.
But I ran into the roadblock of not being able to cast to this interface because it wasn't a blueprint
type.
So we had to go back into the interface and add blueprint type.
So that got me that far.
But then I couldn't call update facing Target as it wasn't Blueprint callable, so I went back into
the interface and gave it blueprint callable.
So now we can see that blueprint.
Implementable events that are blueprint callable can be in our interfaces.
They can't be virtual, you can't mark it as virtual here if it's a blueprint implementable event,
just like a blueprint, Native event can't be marked virtual either.
So we got that working and let's see if it works in the editor.
I'm going to hold shift and click and we rotate it.
Let's try on the client shift.
Click and we rotate.
Perfect.
So this is working and our firebolt is now no longer dependent on a character.
That means we could potentially cast this spell from an enemy if the enemy implements update facing
target and has that function to call.
And we also can't cast this spell, or at least we can't get past this node if the cast to combat interface
fails.
So whoever's activating this ability very much has to implement combat interface.
If we wanted it to be able to not implement it, we could simply hook up.
Cast failed into play montage and wait like that.
But I see no need for that.
I'm okay with my ability requiring the combat interface.
And now our ability is looking a lot better.
It's by no means done, but it's looking better.
And we have a couple of nodes here.
We can remove those and things are looking great.
Okay, so great job on the quest and I'll see you in the next video.