WEBVTT

00:00.110 --> 00:00.650
Hello guys.

00:00.650 --> 00:01.580
Welcome to the video.

00:01.580 --> 00:04.520
In this one we're going to make a trunk enemy.

00:04.970 --> 00:09.680
It's basically a mix of a mushroom enemy and plant enemy.

00:09.710 --> 00:10.850
You're going to walk left and right.

00:10.850 --> 00:12.650
And when he sees you he's going to shoot.

00:12.650 --> 00:13.640
Simple as that.

00:15.350 --> 00:17.930
Let's go and take the mushroom.

00:18.890 --> 00:20.450
I'm going to duplicate him.

00:20.900 --> 00:24.050
Let's do prefab unpack completely.

00:24.590 --> 00:27.200
And let's call him Enemy Trunk.

00:30.210 --> 00:36.360
Then we need to take all of the sprites, make pixel per unit 16, and also we want to take idle sprite

00:36.360 --> 00:37.920
and drag it to the.

00:38.720 --> 00:40.880
Sprite renderer over here.

00:42.380 --> 00:43.130
Okay, cool.

00:43.130 --> 00:46.580
Now let's reset the collider and let's remove this script.

00:48.370 --> 00:49.990
Gonna reset the collider.

00:52.510 --> 00:55.030
I think we can adjust it to something like.

00:56.700 --> 00:57.540
This.

00:59.490 --> 01:01.350
And for damage trigger.

01:02.400 --> 01:04.290
I guess we can just keep it as it is.

01:04.290 --> 01:05.520
This is good enough.

01:05.520 --> 01:06.750
Yeah, I like it.

01:11.050 --> 01:13.090
Okay, now let's make animator.

01:13.090 --> 01:15.700
We're going to go to animations enemies.

01:15.700 --> 01:18.130
Let's make trunk folder.

01:19.840 --> 01:24.220
Then inside we're going to need animator controller, enemy trunk AC.

01:27.240 --> 01:30.210
We're going to put it on the animator over here.

01:30.840 --> 01:33.450
Then in the animations we need to make new clip.

01:35.290 --> 01:36.130
Let's do.

01:37.140 --> 01:38.940
Enemy trunk idol.

01:40.660 --> 01:43.960
We're going to go to graphics over here.

01:44.820 --> 01:45.780
Enemies.

01:47.080 --> 01:48.010
Trunk.

01:48.010 --> 01:51.220
And we're going to take all of these sprites over here.

01:53.200 --> 01:54.970
Sample array 20.

01:55.300 --> 01:57.220
Then we need enemy.

01:58.330 --> 02:00.130
Trunk move.

02:02.730 --> 02:05.220
We're going to take these animations over here.

02:05.220 --> 02:05.940
Drag them.

02:05.940 --> 02:07.200
Sample rate 20.

02:08.400 --> 02:09.120
Okay.

02:09.210 --> 02:10.290
Now let's, uh.

02:10.290 --> 02:11.280
What is that?

02:12.400 --> 02:14.740
That is part of the animation or that is the enemy.

02:14.740 --> 02:15.520
What is that?

02:16.360 --> 02:18.400
That is the enemy going to place him here.

02:18.400 --> 02:19.780
I don't know how that happened.

02:20.960 --> 02:23.690
Anyway, so we have Trunk Idol.

02:25.180 --> 02:26.590
And try and move.

02:27.350 --> 02:27.920
Okay.

02:27.920 --> 02:32.210
Now we're going to add enemy trunk hit.

02:34.410 --> 02:36.510
There is the hit animation.

02:38.240 --> 02:39.680
Sample rate 20.

02:39.680 --> 02:41.840
And we're going to need attack animation.

02:41.840 --> 02:43.400
So I'm going to make a new clip.

02:44.100 --> 02:46.290
Enemy trunk attack.

02:47.280 --> 02:48.390
Let's take these.

02:49.210 --> 02:50.260
Drag them here.

02:50.260 --> 02:51.970
Sample rate 20.

02:52.000 --> 02:55.420
Now we're going to go to assets animations enemies.

02:56.370 --> 02:57.180
Trunk.

02:57.180 --> 03:01.740
And we're going to just take these actually attack and hit and uncheck loop time.

03:02.280 --> 03:03.780
Now let's set up animator.

03:03.780 --> 03:05.400
We're going to open the animator.

03:05.400 --> 03:08.730
And it's not visible for me because I need to restart unity.

03:08.730 --> 03:09.630
That's what I'm going to do.

03:09.630 --> 03:11.130
Let me save the project.

03:11.130 --> 03:11.850
All right.

03:11.850 --> 03:13.200
Here is the animations.

03:13.200 --> 03:18.120
Let's make a float variable for the blend tree x velocity.

03:18.670 --> 03:21.400
And we need trigger for the hit.

03:22.240 --> 03:25.600
And then we need trigger for the attack.

03:26.740 --> 03:27.400
Okay.

03:27.400 --> 03:29.980
We're going to make blend tree for the idle and move.

03:29.980 --> 03:32.680
So I'm going to do idle move.

03:33.310 --> 03:34.900
Let's open the blend tree.

03:35.350 --> 03:37.600
Here we're going to need three motion fields.

03:40.670 --> 03:41.840
Minus one.

03:43.470 --> 03:44.310
Minus one.

03:44.340 --> 03:45.030
Zero.

03:45.030 --> 03:45.840
One.

03:45.840 --> 03:48.150
Or we can take, uh, clips from here.

03:48.150 --> 03:50.130
So let's place move.

03:50.870 --> 03:53.030
Idle move.

03:53.030 --> 03:53.930
Very well.

03:53.930 --> 03:55.160
So this is going to work.

03:55.160 --> 03:57.530
Let's go and make this by default.

03:57.860 --> 04:03.230
Now we can remove these two from here and then we can take I'm sorry.

04:05.010 --> 04:11.970
Trunk attack with transfer to the attack from idle move if trigger of the attack was called with the

04:11.970 --> 04:17.340
exit diamond check and transition duration zero and we're going to transfer to idle move with the exit

04:17.340 --> 04:18.270
time one.

04:18.960 --> 04:21.180
And transition duration zero.

04:21.180 --> 04:22.140
Very good.

04:22.140 --> 04:28.590
Now this enemy trunk heat can be transferred to from any state with an unchecked can transit to self

04:28.590 --> 04:29.520
transition duration.

04:29.520 --> 04:32.940
Zero condition should be heat triggered.

04:33.780 --> 04:34.470
Very nice.

04:34.470 --> 04:35.520
Animator is ready.

04:35.520 --> 04:36.900
It is on the enemy.

04:36.930 --> 04:39.030
Now let's go and make a script.

04:39.270 --> 04:39.720
Assets.

04:39.720 --> 04:40.800
Scripts.

04:41.700 --> 04:43.500
I'm going to make a new one.

04:45.520 --> 04:47.620
Enemy trunk.

04:49.570 --> 04:50.650
Let me open this.

04:50.650 --> 04:52.840
I'm going to do close all but this for now.

04:53.320 --> 04:54.790
And we're going to just.

04:55.410 --> 04:57.030
Inherit from the enemy.

04:59.720 --> 05:00.410
Very well.

05:00.410 --> 05:03.170
Now let's think how it's going to work.

05:03.200 --> 05:05.360
Enemy trunk is basically like a mushroom.

05:05.360 --> 05:06.710
He walks left and right.

05:06.710 --> 05:11.870
Only the difference is that when he detects the player, he's going to stop the movement and he's going

05:11.870 --> 05:13.040
to attack the player.

05:13.040 --> 05:14.330
That's what we're going to do.

05:15.110 --> 05:20.480
So I guess we can go to enemy mushroom and take the code from here.

05:20.480 --> 05:21.620
Let's take it.

05:21.620 --> 05:24.020
Go back to enemy trunk, place it here.

05:26.990 --> 05:30.800
And we can basically utilize most of the script from here.

05:31.010 --> 05:34.310
And let's just go to enemy plant.

05:35.930 --> 05:37.520
We're going to take the header.

05:37.820 --> 05:40.010
I'm going to just copy the header on the enemy trunk.

05:40.010 --> 05:44.780
I'm going to paste the header and change it to trunk details.

05:46.210 --> 05:47.380
Tracking details.

05:47.380 --> 05:48.100
Okay.

05:49.730 --> 05:51.920
Then let's go to enemy plant again.

05:51.920 --> 05:52.790
And just.

05:53.500 --> 05:56.230
Copy these three methods.

05:57.280 --> 05:58.150
Yet these two methods.

05:58.150 --> 05:59.080
I'm going to copy them.

05:59.080 --> 06:00.490
Go to enemy mushroom.

06:01.000 --> 06:01.360
Sorry.

06:01.360 --> 06:02.170
Enemy trunk.

06:03.580 --> 06:05.110
Paste them in here.

06:06.570 --> 06:09.330
And then we need to go to enemy plant again.

06:09.330 --> 06:14.160
Take this code, copy it, go to enemy rank.

06:14.970 --> 06:17.910
Paste it in here.

06:19.170 --> 06:23.850
As I said, it's just a mix of two enemies basically, so we don't really need to change much here.

06:23.850 --> 06:30.840
Only thing I want to do is to trigger idle time every time trunk is attacking, so enemy will stand

06:31.410 --> 06:34.080
at one place and not move for a while.

06:35.300 --> 06:35.600
Okay.

06:35.600 --> 06:36.680
That's what I want to do.

06:36.680 --> 06:38.030
So maybe.

06:38.030 --> 06:40.280
Yeah, we use idle timer here.

06:40.280 --> 06:43.880
So I think we can go to attack method.

06:43.880 --> 06:45.710
And over here I'm going to do.

06:47.970 --> 06:50.610
Idle timer is equal to.

06:52.210 --> 06:57.700
And here we need ideal duration, but maybe a bit longer than idle duration.

06:57.700 --> 07:00.610
Let's try with ideal duration only for now.

07:01.080 --> 07:05.940
So what's the logic here is when he sees the player he's going to attack.

07:05.940 --> 07:08.700
And at that time we're going to trigger idle timer.

07:08.700 --> 07:13.500
Because of that handle, movement will not work and he'll stand at one place.

07:13.500 --> 07:15.150
Once idle timer is over.

07:15.150 --> 07:21.720
He's going to keep moving until he detects the player again or until he detects the ledge or a wall.

07:22.080 --> 07:22.770
Okay.

07:24.350 --> 07:24.770
Hmm.

07:25.640 --> 07:27.260
Let's go back to unity.

07:30.590 --> 07:31.940
You're going to take enemy trunk.

07:31.940 --> 07:33.950
Let's find attack animation.

07:34.670 --> 07:36.860
You're going to find a place of his attack.

07:36.860 --> 07:38.750
So it's here.

07:38.780 --> 07:41.690
I'm going to add event of.

07:41.870 --> 07:42.320
Oh, sorry.

07:42.320 --> 07:44.930
We need to place the script on enemy trunk.

07:45.660 --> 07:46.290
Okay.

07:46.290 --> 07:49.830
So we're going to add event of method.

07:50.660 --> 07:52.070
Three bullet.

07:53.290 --> 07:54.520
Then on the enemy trunk.

07:54.520 --> 07:55.360
What is ground?

07:55.360 --> 07:56.410
Ground?

07:56.860 --> 07:58.090
What is player?

07:58.090 --> 08:02.380
Player and ground check is long enough, so it's okay.

08:02.380 --> 08:04.390
I'm going to take the ground check itself.

08:04.720 --> 08:08.020
Place it in front of the enemy here.

08:08.020 --> 08:10.720
Then let's assign it over here.

08:11.200 --> 08:13.930
And let's assign gunpoint, which we don't have yet.

08:13.930 --> 08:16.600
So I'm going to make one gunpoint.

08:17.740 --> 08:19.330
Gunpoint should be here.

08:20.530 --> 08:25.510
We can drag it to the gun point over here and we'll check distance.

08:25.870 --> 08:29.500
I cannot see it because of a player detection, so I'm going to make it zero for now.

08:29.920 --> 08:30.640
Now I can see.

08:30.640 --> 08:31.780
We'll check distance.

08:33.070 --> 08:34.090
So I guess we'll check.

08:34.090 --> 08:39.100
Distance eight is fine and then player detection 15 is fine as well.

08:39.340 --> 08:44.260
Now we need a bullet for this enemy before we test everything, because I think it's going to work anyway.

08:44.470 --> 08:46.960
Let's go to asset prefab.

08:46.960 --> 08:48.700
There is an enemy bullet.

08:48.700 --> 08:50.080
I'm going to drag it here.

08:50.080 --> 08:53.290
Change the name to enemy.

08:54.090 --> 08:55.890
Bullet plant.

08:56.510 --> 08:57.740
Let's apply.

08:57.950 --> 08:58.520
We cannot apply.

08:58.520 --> 08:58.880
Override.

08:58.880 --> 08:59.450
Okay.

08:59.660 --> 09:01.640
Uh, how can we solve this?

09:01.670 --> 09:04.820
We're going to just take it away from here.

09:05.360 --> 09:10.910
Do prefab, unpack completely, then drag it here again as a prefab on the enemy plant.

09:10.910 --> 09:13.370
We need to reassign bullet over here.

09:13.370 --> 09:14.450
So this is good.

09:14.450 --> 09:19.640
Now I can take this, uh, bullet change to enemy bullet trunk.

09:20.810 --> 09:24.110
Go to, uh, let's do prefab and completely.

09:24.770 --> 09:26.780
So now this is a new object.

09:26.780 --> 09:29.570
You're going to go to graphics of the enemy trunk.

09:30.710 --> 09:32.330
Take the bullet sprite.

09:33.810 --> 09:35.010
Place it here.

09:36.110 --> 09:37.940
And then we're going to just.

09:42.180 --> 09:49.920
And then we're going to just, uh, go to prefab again, drag it here, and then give this bullet to

09:49.920 --> 09:52.410
the enemy trunk over here.

09:52.410 --> 09:53.100
Okay.

09:53.100 --> 09:57.660
Now it can be deleted from the scene, and I guess it should be fine.

09:57.660 --> 09:58.260
Now.

09:58.620 --> 10:00.150
It has idle time.

10:00.150 --> 10:01.500
It has movement speed.

10:01.500 --> 10:02.640
Everything is ready.

10:02.640 --> 10:04.110
Let's go to play mode.

10:05.680 --> 10:06.970
So he walks.

10:07.790 --> 10:09.020
Here and there.

10:09.440 --> 10:13.040
He flips now he sees me and he attacks.

10:14.760 --> 10:16.410
Very cool, I like it.

10:18.880 --> 10:21.550
Now, if I go away from the.

10:25.610 --> 10:28.430
Like I can see he does a little bit of a step.

10:29.310 --> 10:36.510
That's why I said we need longer idle duration, longer than the, uh, usually we have, I think.

10:37.200 --> 10:38.640
We can go there.

10:38.640 --> 10:39.270
Sorry.

10:39.270 --> 10:40.350
Where is the enemy trunk?

10:40.350 --> 10:41.130
Here.

10:41.130 --> 10:45.330
And we can do idle duration plus attack cooldown.

10:45.810 --> 10:47.790
Yeah, this is a bit better.

10:47.790 --> 10:52.080
And also I've seen, like, feels like bullet is in front of the enemy.

10:52.080 --> 10:58.020
So I'm going to go to the prefab of the bullet enemy trunk sprite renderer.

10:58.020 --> 11:00.690
I'm going to do order in layer minus one.

11:02.060 --> 11:03.530
Also, I want to flip the bullet.

11:03.530 --> 11:05.630
Let me check how it is flying right now.

11:06.540 --> 11:09.090
So when it goes to the left, it's fine.

11:10.590 --> 11:12.750
Um, but if I stand on the right.

11:13.550 --> 11:15.140
Wait for him to go back.

11:15.170 --> 11:15.680
Yeah.

11:15.680 --> 11:18.950
Now it's supposed to be facing another direction, I believe.

11:18.980 --> 11:23.270
So what we can do here is to flip the bullet every time we create it.

11:23.270 --> 11:24.680
Let's go to enemy trunk.

11:26.640 --> 11:30.750
Uh, here is a bullet we have, so maybe we can make a method on the bullet.

11:30.750 --> 11:32.400
Let's do peak definition.

11:32.700 --> 11:34.800
Actually, let's just go to definition.

11:36.160 --> 11:36.340
Hmm?

11:36.370 --> 11:36.790
Come on.

11:36.790 --> 11:37.180
Man.

11:37.210 --> 11:37.630
Enemy.

11:37.630 --> 11:37.930
Bullet.

11:37.960 --> 11:39.040
Go to definition.

11:39.040 --> 11:39.700
Okay.

11:40.210 --> 11:40.810
Over here.

11:40.810 --> 11:43.240
I'm going to do private sprite renderer.

11:43.300 --> 11:44.080
SR.

11:44.830 --> 11:47.260
SR equals to get component of a sprite renderer.

11:47.260 --> 11:52.420
And then I'm going to do public void flip sprite.

11:53.520 --> 12:01.290
And I'm going to do just SR dot flip x equals to not sr flip x okay.

12:01.530 --> 12:04.230
Now we can go back to enemy trunk.

12:04.230 --> 12:06.660
And I think I can do close all but this.

12:06.660 --> 12:11.070
And over here I'm going to check if facing direction is equals to one.

12:11.220 --> 12:13.470
Which means we are facing to the right.

12:13.470 --> 12:16.230
Then new bullet flip sprite.

12:16.230 --> 12:16.980
Just that.

12:16.980 --> 12:18.780
And I guess it's basically ready.

12:18.780 --> 12:20.430
We can go back to unity.

12:20.430 --> 12:26.460
And because we had most of the functionality on other enemies, we just had to flip parameters a little

12:26.460 --> 12:27.060
bit.

12:27.690 --> 12:29.490
Let's go to play mode.

12:34.050 --> 12:34.380
Okay.

12:34.380 --> 12:35.220
He shoots me.

12:35.220 --> 12:36.450
This is nice.

12:36.480 --> 12:39.570
Now I'm going to wait for him to go and flip himself.

12:42.300 --> 12:44.010
And he flips the bullet as well.

12:44.010 --> 12:45.060
Very cool.

12:45.150 --> 12:46.680
And can we kill him?

12:46.680 --> 12:47.580
Let me check.

12:50.210 --> 12:50.720
Boom!

12:50.930 --> 12:51.740
Yay!

12:51.830 --> 12:52.670
Very good.

12:52.700 --> 12:53.780
I love it, man.

12:54.140 --> 12:56.570
So, believe me or not, it's done.

12:56.570 --> 12:57.590
He's ready.

12:57.710 --> 12:59.480
Let's go to prefabs.

12:59.780 --> 13:02.750
Let's make enemy prefab over here.

13:02.750 --> 13:04.970
And I'm going to delete it from the scene.

13:04.970 --> 13:07.070
And we're good to go to the next video.
