Welcome to the next quest.
Now we're going to want to play the ranged attack montage, so I'd like you to handle that in our ranged
attack ability.
Go ahead and play that montage.
Make sure you get it similarly to how we did our melee attack.
Now, I'd like you to also take care of motion warping, so make sure that our ranged attacker will
rotate towards aura when shooting and as a bonus, respond to the event.
We know that we're sending a gameplay event from our montage.
If you feel so inclined, respond to that event.
And if you really want to get ambitious, see if you can get the correct weapon socket location.
Taking into account all the things you need to do there and draw a debug sphere at the slingshot pouch.
So lots of additional optional mini challenges in there for you as well.
So pause the video and conquer this quest now.
All right.
So I'm here in my ranged attack, and I think I'd like to just move this draw debug sphere up and out
of the way just in case I want to use it later.
But for now, I'd like to play a montage.
Now, if I look at my melee attack, I'll see that I'm getting the avatar actor and using the interface
function get combat target.
And from that combat target we're getting it's actor location and using that to update the facing target
using the combat interface function update facing target.
Let's see if we can do that same thing here in our range attack.
So first I'm going to get Avatar actor from actor info and I'm going to get its combat target.
So I'm going to call get combat target.
This requires that actor and it returns an actor object reference.
So we're going to get that combat target and I'm going to get its location with get actor location.
Now, next, we can update the facing target by calling update, facing target and passing in the target
location.
But make sure that this target is actually the owner of the interface.
Right.
We don't want to pass in the combat target.
It's a little confusing that this is called Target.
But look at our melee.
You'll see that we're calling update facing Target.
And notice I didn't have to cast to the combat interface.
That's because if we go back to our combat interface here in public interaction, Combat Interface update,
facing Target is actually a blueprint, implementable blueprint callable, and we can just call it directly
like this.
So after updating the facing target, we can then do what we did in the melee attack.
We can get the attack montages from the combat interface.
So let's do that.
We're going to call get attack montages.
We're going to plug in the Avatar actor.
So I'm going to duplicate that, plug that in.
And we now want a random attack montage.
Now this right here is a little bit messy.
I'd really like for our aura damage gameplay ability to be able to do that for us.
Just take in an array of this type and return one of them at random and perhaps return an empty struct
for the tagged montage if this array is empty or doesn't contain anything.
So I think that is something I'd like to create a blueprint callable function for so that we don't have
to just copy all these nodes and paste them in here.
So for that reason I'm going to go back into our C plus plus ability and ability system abilities and
I'm going to add this to aura damage gameplay ability because it has the damage capabilities.
I'm going to add a new function here and this function is just going to take in an array of tagged montage
structures and it's going to return one of those tagged montages.
So it'll return an F tagged montage.
I'm going to add the include for that and call this get random tagged montage from array and it'll take
a const t array of f tagged montages.
And it'll take it in by const reference.
And I'll call this tagged montages.
And this will be a new function and we can make this blueprint pure.
So let's go ahead and generate the definition for this.
And it's going to be quite simple.
It's going to do exactly what our blueprint nodes are doing.
It's going to check the length of the array, make sure it's not zero.
So we're going to say if tagged montages dot num is greater than zero and at the very end, we're just
going to return an F tagged montage that's empty.
But if the tagged montage is array is not empty, well then what we're going to do is we're going to
get the length of the array minus one and get a random integer.
So we're going to say int 32, this could be const, actually we'll call it selection equals F math
rand range.
Rand range needs a minimum and a maximum.
We're going to go from a minimum of zero to tagged montages, dot numb minus one.
And then we're going to return tagged montages, indexing it with selection.
So now we have this nice function we can call and of course it can be const.
So let's go ahead and just make that a const function.
There we go.
And this blueprint, pure function can be used instead of all those nodes.
So I'm going to close out of the editor saving all my progress and then just go ahead and launch again.
I'm just going to click Run.
And we'll go ahead and open up our asset editors.
I'm going to go back to my melee and use my get random tagged montage from array and use this instead
now.
So I'm going to plug that array straight in.
Target is self and the return value is the actual tagged montage that we're going to store.
And I don't need the rest of these nodes and I don't actually want my branch either.
So I'm going to delete any ability, delete the branch.
And delete these nodes.
And this is a lot cleaner.
Okay, So we're going to do something similar here in the ranged attack.
So here's my GA ranged attack.
Looks like it got stuck on the other side of all those tabs.
So after getting attack montages, we're going to call get random tagged montage from array.
Get random tagged montage from array.
Hooking in that array and the return value can be promoted to a variable called tagged montage.
Once we have that, we can go ahead and play a montage and wait.
So I'm going to use that ability task play montage and wait.
Using the montage in our tagged montage.
So we're going to break it.
And expose that montage.
I'm going to uncheck Stop when ability Ends.
I'd like that montage to keep playing until it's over and we have the montage tag as well.
So that has to do with kind of a bit of the bonus challenge where we wait for the gameplay event.
For now though, let's just make sure that play montage and wait works and we do need our goblin slingshot
to have its attack montages.
I know I added it, but I'm going to show you that I'm double checking it just to make sure.
So we should be able to see that montage get played in our ranged attack.
Let's go ahead and just save all and try that.
So here are the ranged attackers hanging back.
And there they are.
They are attacking that walls in the way.
I'm going to go ahead and get rid of it.
And now we should be able to see those ranged attackers.
And yes, they are attacking and in fact, their motion warping looks like it's working as well.
They're orienting towards our enemy or towards their enemy, I should say, as they attack with their
slingshots.
So that's looking great.
Now for the optional bonus part of the challenge, we could wait for a gameplay event so we can drag
right off of this use wait gameplay event.
And the tag that we're going to wait for is the tag associated with our montage.
So let's reroute this.
Wire around.
And drag it in for our wait gameplay event.
Make sure that it's matching exact.
And just like in our melee attack, once the event is received, we can get the combat socket location
using that tag and we're going to just draw a debug sphere for now.
So on event received, we're going to call get combat socket location.
Passing in the tag for the montage tag there.
I'll go ahead and reroute that node right there.
Now we need a target for this.
And just like in Melee, we could use get Avatar actor from actor info.
Let's go ahead and use that.
Get avatar actor from actor info.
We're getting the combat socket location, which means we need to make sure that our goblin slingshot
has its weapon tip socket name set.
Now, to make this easy so we don't forget in the future, I could just set the base enemy weapon,
tip socket name to tip socket and just use that for all of my enemies.
So I'd like to do that.
I'm going to go to Blueprints Character BP Enemy base and search for weapon tip socket name and set
that to tip socket.
And that way in all of my child classes, they're set to tip socket unless I overwrite them.
But now we are using tip socket for all of our enemies and that is going to ensure that things work
as long as our enemies are using that socket name.
Now, first, I should make sure I'm not breaking my spear goblin, so I'm going to go into enemies
under assets, goblin, Spear and open my static mesh spear.
And it says it's called tip socket.
And we renamed the base enemies weapon tip socket name to tip socket.
So that works.
Now that works if everything is called tip socket, right?
But if we look at the static mesh for the slingshot, it has a bone called pouch.
We're going to need that socket.
So we'll add a socket and this socket should be called tip socket.
Either that or we could call it pouch socket if we wanted to.
But if we do that, we do have to go into Goblin Slingshot and make sure it's called pouch socket here.
So it's up to you if you want it to be called pouch socket and you just overwrite this in goblin slingshot,
use tip socket for all the others.
It's up to you.
So if you want you can just use tip socket for everything.
But it makes more sense.
I think if the pouch socket is called pouch socket up to you.
Now that we set that correctly in our ranged attack get combat socket location should return a socket
location and I saved my draw debug sphere up here.
I'm going to use that passing in the combat socket location.
So that we can see that.
But I'm going to change it to a red color and draw it a little smaller.
Let's do 20 for the radius and let's see if we can see the combat socket location.
Let's make sure that that's correct.
So saving all and getting our enemies close.
And there we go.
They're attacking.
And that combat socket location looks correct.
We can really hone in on it by setting its radius to a really small value like five and seeing if it
looks pretty much perfect.
And yes, it does look like it's right there at the socket.
On the pouch.
Perfect.
Okay, so we're one step closer.
We're now playing our montage.
We're receiving the event, we're getting the correct socket location.
Everything is looking nice.
We still want to spawn a rock projectile.
So a couple things left.
And of course, we do want our slingshot itself to be stretchy and look like that pouch is being held
and released.
So quite a few things left for our range attacker.
We're getting there.
Excellent job.
I'm going to save all and I'll see you in the next video.