WEBVTT

00:06.810 --> 00:07.890
Welcome back.

00:07.920 --> 00:16.260
Now that we have our enemies firing projectiles, it's time for some of the slightly more cosmetic aspects

00:16.260 --> 00:16.980
of this.

00:17.010 --> 00:22.050
We want our slingshot enemies to actually fire a slingshot.

00:22.080 --> 00:24.760
We want that slingshot to stretch.

00:24.780 --> 00:27.070
We want them to be holding the pouch.

00:27.090 --> 00:30.060
We don't want this to be just a static weapon.

00:30.060 --> 00:32.640
We want it to be dynamic and changing.

00:32.790 --> 00:36.720
So we're going to do that over the course of these next couple videos.

00:36.990 --> 00:42.870
Now, what I can do is start closing down some of these tabs that I don't need open.

00:44.850 --> 00:48.450
So I'm going to go ahead and just close a bunch of them down.

00:48.570 --> 00:55.650
Now let's right click on one of these goblins and just edit that goblin blueprint so we can see what

00:55.650 --> 00:56.730
it looks like here.

00:56.760 --> 00:59.220
Now here's our idle animation.

00:59.220 --> 01:06.630
And if we're idling, well, I think our goblin should be holding the pouch and we know the pouch can

01:06.630 --> 01:12.280
stretch, or at least the cord that the pouch is stuck to that can stretch.

01:12.300 --> 01:16.770
So we need to figure out exactly how we can make that happen.

01:16.770 --> 01:19.530
And our slingshot is a skeletal mesh.

01:19.530 --> 01:24.780
And for that reason, we can have an animation blueprint for our slingshot.

01:24.780 --> 01:31.320
So I'd like to do that so we can have a little bit of control over the slingshot bone position, specifically

01:31.320 --> 01:32.250
the pouch.

01:32.580 --> 01:37.860
So we're going to make an animation blueprint for our slingshot.

01:38.430 --> 01:46.270
So I'm going to go into Blueprints, Character Goblin Slingshot, and we're going to make a new animation

01:46.270 --> 01:47.320
blueprint here.

01:47.500 --> 01:52.720
I'm just going to right click, go to animation and choose animation Blueprint, and we're going to

01:52.720 --> 02:01.360
choose the skeleton for our slingshot and create this and call this a BP underscore slingshot.

02:01.780 --> 02:05.430
So now we have an animation blueprint for the Slingshot.

02:05.440 --> 02:06.960
Pretty interesting.

02:06.970 --> 02:11.940
Now we're going to have just a basic pose for our slingshot.

02:11.950 --> 02:15.610
So our anim graph is going to be quite simple.

02:15.700 --> 02:20.650
We'll have a state machine, so we're going to right click make a state machine.

02:24.030 --> 02:25.890
I'm just going to call it Maine.

02:26.460 --> 02:30.480
And in Maine, we're going to have a single state.

02:30.480 --> 02:33.600
And our slingshot has an idle animation.

02:33.600 --> 02:35.160
And really, it's nothing.

02:35.160 --> 02:36.030
It doesn't do anything.

02:36.030 --> 02:37.920
It's a single frame like this.

02:37.920 --> 02:40.920
It's just a default animation.

02:40.920 --> 02:42.570
That's what our state will be.

02:42.570 --> 02:49.020
We'll have slingshot idle, the entry will go into that, and then our main will go into the output

02:49.020 --> 02:49.830
pose.

02:49.830 --> 02:52.140
But we do have an attack.

02:52.140 --> 02:54.090
Animation looks like this.

02:54.120 --> 02:56.850
We're going to be making an attack montage.

02:56.850 --> 03:01.980
So we do want to run this through a slot and we're just going to use the default slot.

03:02.010 --> 03:04.560
So there's our animation blueprint.

03:04.590 --> 03:06.900
So this is pretty simple, pretty basic.

03:06.900 --> 03:08.760
We're not doing anything too crazy, right?

03:08.760 --> 03:11.520
So why do we need an animation blueprint?

03:11.550 --> 03:17.430
Well, the reason is we can control bone positions with our animation blueprint.

03:17.430 --> 03:26.290
And I'd like my bone position to follow the bone position of the goblin that's holding the slingshot.

03:26.290 --> 03:29.410
So the question is, how are we going to do that?

03:29.440 --> 03:36.430
Well, for one, we need to know the transform location rotation of our owner's hand.

03:36.520 --> 03:43.210
We should have at least a socket on the owning goblin that is on its right hand.

03:43.210 --> 03:43.510
Right?

03:43.510 --> 03:50.440
So let's go to our goblins, mesh the skeletal mesh and open that up and let's just see what we have.

03:50.440 --> 03:53.380
We have a socket on the left hand.

03:53.380 --> 03:55.390
It's called weapon hand socket.

03:55.420 --> 04:00.670
We don't have anything on the right hand, but we should because that right hand is going to hold the

04:00.670 --> 04:01.570
pouch.

04:01.570 --> 04:06.040
So I'm going to select that hand hand.

04:06.040 --> 04:11.440
And look, we have actually a socket right there called hand our socket.

04:11.440 --> 04:12.520
That's fine.

04:12.520 --> 04:14.260
If we want, we can rename that.

04:14.260 --> 04:16.450
Let's go ahead and rename it to something better.

04:16.450 --> 04:19.960
I'm going to call it right hand socket.

04:20.260 --> 04:24.070
So our right hand has the right hand socket on it.

04:24.070 --> 04:28.750
Right there and we can position it if we want to change that position.

04:28.750 --> 04:32.830
But I think it looks good and we want to know the location of that.

04:32.980 --> 04:39.460
So here in the animation blueprint for the Slingshot, we need to access the owning pawn and get its

04:39.460 --> 04:40.270
skeletal mesh.

04:40.270 --> 04:45.010
And from that mesh we need to get that socket location for the right hand socket.

04:45.130 --> 04:48.370
So we'll do all this here in the event graph.

04:48.400 --> 04:54.640
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

04:54.640 --> 04:59.380
cast it to a character so we can get its skeletal mesh component.

04:59.380 --> 05:01.720
So what I'm going to do is cast a character.

05:02.450 --> 05:04.520
After casting two character.

05:04.550 --> 05:10.280
I'm going to get the characters mesh using get mesh.

05:11.730 --> 05:13.460
From the characters Mash.

05:13.470 --> 05:19.140
I'm going to try to access one of the sockets by calling Get Socket Transform.

05:19.530 --> 05:22.640
Transform will return us a transform.

05:22.650 --> 05:29.130
Now the socket will be retrieved by name and we know that the right hand socket is called right hand

05:29.160 --> 05:29.850
socket.

05:29.850 --> 05:35.670
So we're going to select right hand socket here and we can choose transform space.

05:35.670 --> 05:41.340
I'd like to use world space Now this is in Blueprint update animation.

05:41.340 --> 05:46.830
So we're kind of casting every frame, so it'd be nice to store this just once at the beginning so we

05:46.830 --> 05:52.530
don't have to cast every frame and then every frame we could be setting some variable.

05:52.530 --> 05:59.400
We can promote this transform to a variable and call this hand socket transform.

06:00.490 --> 06:02.590
And it looks like I put a comma there.

06:03.070 --> 06:04.330
No commas.

06:04.720 --> 06:07.570
Okay, so we don't want to cast every frame.

06:07.570 --> 06:15.760
We can initialize this at the beginning by overwriting this at the beginning, by implementing event

06:15.760 --> 06:18.820
blueprint, initialize animation.

06:18.820 --> 06:22.000
So I'd like to move this cast up there.

06:28.240 --> 06:36.100
And what we can do is we can simply store a variable that we can get the socket transform from every

06:36.100 --> 06:36.820
frame.

06:36.820 --> 06:43.540
So it might be handy to just take the character call, get mesh on it, and from that mesh, promote

06:43.540 --> 06:47.830
that to a variable called owner mesh.

06:49.800 --> 06:56.040
Like so and then we can just get that socket transform from owner mesh every frame.

06:56.920 --> 06:58.390
So right there.

06:59.120 --> 07:05.060
Getting the owner mesh and updating socket transform or hand socket transform.

07:05.060 --> 07:10.420
So every frame we're getting this socket transform, we want to use that socket transform somehow.

07:10.430 --> 07:12.320
So how are we going to use that?

07:12.620 --> 07:20.240
Well, we can go to our anim graph and before running our state through the default slot and the output

07:20.240 --> 07:24.130
pose, we can modify one of its bones.

07:24.140 --> 07:27.770
We can use a transform modify bone node.

07:27.770 --> 07:36.380
So if we right click and type transform, modify bone, then this node allows us to transform a bone

07:36.380 --> 07:40.520
based on some translation, rotation and scale.

07:40.520 --> 07:47.960
And if we get our hand socket transform and we break that transform or we split the struct pin, we

07:47.960 --> 07:50.060
can then plug these values in.

07:50.090 --> 07:56.090
The transform location can be plugged into translation, rotation to rotation and scale.

07:56.090 --> 07:57.080
We can leave that at one.

07:57.080 --> 08:02.370
We don't need to change the scale for anything, but we'd like to transform our pouch bone.

08:02.370 --> 08:08.580
So if I select transform, modify Bone in the Details panel, we can configure this node and the bone

08:08.580 --> 08:09.450
to modify.

08:09.450 --> 08:17.460
I would like to be my pouch bone and I'd like to modify its translation and rotation so we can expose

08:17.460 --> 08:18.750
more of this details.

08:18.750 --> 08:24.870
Panel And for translation I want to replace the existing translation.

08:24.870 --> 08:31.590
So translation mode I can choose replace existing and I want my translation space to be world space.

08:31.620 --> 08:32.070
Why?

08:32.100 --> 08:37.080
Because in my event graph we're getting the socket transform in world space.

08:37.080 --> 08:41.400
So just to make everything consistent, it's going to be world space here.

08:41.400 --> 08:48.090
And for the rotation, I'd like to also replace existing and I'd like this to be in world space as well

08:48.090 --> 08:50.550
and the scale I want to ignore.

08:50.550 --> 08:57.570
So I don't even need my scale exposed as a pin so I can click right here and uncheck expose pin.

08:57.570 --> 09:01.080
And now we don't even care about the scale.

09:01.080 --> 09:04.920
It's not exposed as a pin, so it doesn't matter now.

09:04.920 --> 09:09.360
The alpha is going to be one, so we don't need to expose the alpha either.

09:09.360 --> 09:12.210
We can un expose that as well.

09:12.210 --> 09:20.550
And now our transform modify bone node is a lot simpler and we can use this by running the main state

09:20.550 --> 09:21.930
machine pose through it.

09:21.960 --> 09:28.470
Now this is going to convert from local to component space and then once we go back to the slot, it'll

09:28.470 --> 09:30.780
convert back from component to local.

09:30.780 --> 09:34.080
That's how transform Modify bone has to work.

09:34.080 --> 09:43.380
So now that we have this, we can straighten out our nodes and we have something that will set our bone,

09:43.410 --> 09:45.990
our pouch bone, every frame.

09:45.990 --> 09:54.600
Now if I compile it, that's going to set the pouch to essentially a location in rotation that doesn't

09:54.600 --> 10:01.620
really look like it makes sense, but that's okay, because if we go back to our goblin slingshot and

10:01.620 --> 10:09.420
we select the weapon and we go up into animation mode for the weapon and select an anim class and choose

10:09.450 --> 10:11.010
app Slingshot.

10:11.040 --> 10:12.390
Now look what happens.

10:12.390 --> 10:19.230
The pouch is now following that right hand socket because we're transform modifying the bone.

10:19.260 --> 10:26.880
This is great, but it doesn't really help us In the case where the enemy is playing an attack animation

10:26.880 --> 10:27.540
does it?

10:27.540 --> 10:34.680
If I take my mesh and instead of using an anim class, I switch this to use an animation asset and choose

10:34.680 --> 10:36.780
the attack Goblin slingshot.

10:36.810 --> 10:43.740
We'll see that while yes, the pouch is following the hand and while that may look okay, we want that

10:43.740 --> 10:47.670
pouch to shoot forward when we're attacking, right?

10:47.670 --> 10:50.460
So I'm going to put this back to use animation blueprint.

10:50.460 --> 10:58.290
So this is step one is getting that animation blueprint and controlling that pouch location.

10:58.290 --> 11:03.120
That looks pretty good until we see the enemies attack.

11:03.120 --> 11:12.210
So I'm going to hit pause here and eject and just zoom on in to see that our slingshot enemies do look

11:12.210 --> 11:12.720
pretty cool.

11:12.720 --> 11:17.520
Now with that pouch being held and stretched, it all looks great.

11:17.550 --> 11:19.770
We see that in the idle pose.

11:19.770 --> 11:20.550
It looks great.

11:20.550 --> 11:24.390
But we're going to want to play an attack montage for this.

11:24.420 --> 11:32.250
We're going to want our transform modify bone to not transform modify while we're attacking.

11:32.250 --> 11:37.440
So we have a few details to take care of and we'll be taking care of those next.

11:37.440 --> 11:39.840
So great job and I'll see you soon.
