Welcome back.
Now that we have our enemies firing projectiles, it's time for some of the slightly more cosmetic aspects
of this.
We want our slingshot enemies to actually fire a slingshot.
We want that slingshot to stretch.
We want them to be holding the pouch.
We don't want this to be just a static weapon.
We want it to be dynamic and changing.
So we're going to do that over the course of these next couple videos.
Now, what I can do is start closing down some of these tabs that I don't need open.
So I'm going to go ahead and just close a bunch of them down.
Now let's right click on one of these goblins and just edit that goblin blueprint so we can see what
it looks like here.
Now here's our idle animation.
And if we're idling, well, I think our goblin should be holding the pouch and we know the pouch can
stretch, or at least the cord that the pouch is stuck to that can stretch.
So we need to figure out exactly how we can make that happen.
And our slingshot is a skeletal mesh.
And for that reason, we can have an animation blueprint for our slingshot.
So I'd like to do that so we can have a little bit of control over the slingshot bone position, specifically
the pouch.
So we're going to make an animation blueprint for our slingshot.
So I'm going to go into Blueprints, Character Goblin Slingshot, and we're going to make a new animation
blueprint here.
I'm just going to right click, go to animation and choose animation Blueprint, and we're going to
choose the skeleton for our slingshot and create this and call this a BP underscore slingshot.
So now we have an animation blueprint for the Slingshot.
Pretty interesting.
Now we're going to have just a basic pose for our slingshot.
So our anim graph is going to be quite simple.
We'll have a state machine, so we're going to right click make a state machine.
I'm just going to call it Maine.
And in Maine, we're going to have a single state.
And our slingshot has an idle animation.
And really, it's nothing.
It doesn't do anything.
It's a single frame like this.
It's just a default animation.
That's what our state will be.
We'll have slingshot idle, the entry will go into that, and then our main will go into the output
pose.
But we do have an attack.
Animation looks like this.
We're going to be making an attack montage.
So we do want to run this through a slot and we're just going to use the default slot.
So there's our animation blueprint.
So this is pretty simple, pretty basic.
We're not doing anything too crazy, right?
So why do we need an animation blueprint?
Well, the reason is we can control bone positions with our animation blueprint.
And I'd like my bone position to follow the bone position of the goblin that's holding the slingshot.
So the question is, how are we going to do that?
Well, for one, we need to know the transform location rotation of our owner's hand.
We should have at least a socket on the owning goblin that is on its right hand.
Right?
So let's go to our goblins, mesh the skeletal mesh and open that up and let's just see what we have.
We have a socket on the left hand.
It's called weapon hand socket.
We don't have anything on the right hand, but we should because that right hand is going to hold the
pouch.
So I'm going to select that hand hand.
And look, we have actually a socket right there called hand our socket.
That's fine.
If we want, we can rename that.
Let's go ahead and rename it to something better.
I'm going to call it right hand socket.
So our right hand has the right hand socket on it.
Right there and we can position it if we want to change that position.
But I think it looks good and we want to know the location of that.
So here in the animation blueprint for the Slingshot, we need to access the owning pawn and get its
skeletal mesh.
And from that mesh we need to get that socket location for the right hand socket.
So we'll do all this here in the event graph.
What we're going to do is we're going to get the pawn owner, try to get it, and we need to at least
cast it to a character so we can get its skeletal mesh component.
So what I'm going to do is cast a character.
After casting two character.
I'm going to get the characters mesh using get mesh.
From the characters Mash.
I'm going to try to access one of the sockets by calling Get Socket Transform.
Transform will return us a transform.
Now the socket will be retrieved by name and we know that the right hand socket is called right hand
socket.
So we're going to select right hand socket here and we can choose transform space.
I'd like to use world space Now this is in Blueprint update animation.
So we're kind of casting every frame, so it'd be nice to store this just once at the beginning so we
don't have to cast every frame and then every frame we could be setting some variable.
We can promote this transform to a variable and call this hand socket transform.
And it looks like I put a comma there.
No commas.
Okay, so we don't want to cast every frame.
We can initialize this at the beginning by overwriting this at the beginning, by implementing event
blueprint, initialize animation.
So I'd like to move this cast up there.
And what we can do is we can simply store a variable that we can get the socket transform from every
frame.
So it might be handy to just take the character call, get mesh on it, and from that mesh, promote
that to a variable called owner mesh.
Like so and then we can just get that socket transform from owner mesh every frame.
So right there.
Getting the owner mesh and updating socket transform or hand socket transform.
So every frame we're getting this socket transform, we want to use that socket transform somehow.
So how are we going to use that?
Well, we can go to our anim graph and before running our state through the default slot and the output
pose, we can modify one of its bones.
We can use a transform modify bone node.
So if we right click and type transform, modify bone, then this node allows us to transform a bone
based on some translation, rotation and scale.
And if we get our hand socket transform and we break that transform or we split the struct pin, we
can then plug these values in.
The transform location can be plugged into translation, rotation to rotation and scale.
We can leave that at one.
We don't need to change the scale for anything, but we'd like to transform our pouch bone.
So if I select transform, modify Bone in the Details panel, we can configure this node and the bone
to modify.
I would like to be my pouch bone and I'd like to modify its translation and rotation so we can expose
more of this details.
Panel And for translation I want to replace the existing translation.
So translation mode I can choose replace existing and I want my translation space to be world space.
Why?
Because in my event graph we're getting the socket transform in world space.
So just to make everything consistent, it's going to be world space here.
And for the rotation, I'd like to also replace existing and I'd like this to be in world space as well
and the scale I want to ignore.
So I don't even need my scale exposed as a pin so I can click right here and uncheck expose pin.
And now we don't even care about the scale.
It's not exposed as a pin, so it doesn't matter now.
The alpha is going to be one, so we don't need to expose the alpha either.
We can un expose that as well.
And now our transform modify bone node is a lot simpler and we can use this by running the main state
machine pose through it.
Now this is going to convert from local to component space and then once we go back to the slot, it'll
convert back from component to local.
That's how transform Modify bone has to work.
So now that we have this, we can straighten out our nodes and we have something that will set our bone,
our pouch bone, every frame.
Now if I compile it, that's going to set the pouch to essentially a location in rotation that doesn't
really look like it makes sense, but that's okay, because if we go back to our goblin slingshot and
we select the weapon and we go up into animation mode for the weapon and select an anim class and choose
app Slingshot.
Now look what happens.
The pouch is now following that right hand socket because we're transform modifying the bone.
This is great, but it doesn't really help us In the case where the enemy is playing an attack animation
does it?
If I take my mesh and instead of using an anim class, I switch this to use an animation asset and choose
the attack Goblin slingshot.
We'll see that while yes, the pouch is following the hand and while that may look okay, we want that
pouch to shoot forward when we're attacking, right?
So I'm going to put this back to use animation blueprint.
So this is step one is getting that animation blueprint and controlling that pouch location.
That looks pretty good until we see the enemies attack.
So I'm going to hit pause here and eject and just zoom on in to see that our slingshot enemies do look
pretty cool.
Now with that pouch being held and stretched, it all looks great.
We see that in the idle pose.
It looks great.
But we're going to want to play an attack montage for this.
We're going to want our transform modify bone to not transform modify while we're attacking.
So we have a few details to take care of and we'll be taking care of those next.
So great job and I'll see you soon.