WEBVTT

00:00.080 --> 00:00.590
Hello guys.

00:00.590 --> 00:01.820
Welcome to the next video.

00:01.820 --> 00:05.690
So first of all I noticed something from the last video.

00:05.690 --> 00:08.810
So let's go quickly and fix what I noticed.

00:08.960 --> 00:13.880
Uh, we doing this thing with a collider because we have different colliders on different enemies,

00:13.880 --> 00:20.270
possibly in the future, but I just realized that we can just make a variable of a collider 2D, and

00:20.270 --> 00:22.850
it will assign collider it has on the object.

00:22.850 --> 00:26.630
So let's quickly do here protected Collider 2D.

00:28.210 --> 00:29.380
I'm going to call it CD.

00:31.150 --> 00:35.320
Then in the awake I'm going to do CD equals to get component of a collider.

00:35.590 --> 00:37.900
Should we name it as like coal?

00:38.770 --> 00:40.480
All later we are a bit better.

00:40.480 --> 00:46.690
And then over here we can do call enabled equals to false.

00:46.690 --> 00:51.880
And thanks to this, we don't need to go to enemy mushroom and do override over die method.

00:51.880 --> 00:55.240
And also we don't need this awake and this variable over here.

00:55.240 --> 00:56.050
Very cool.

00:56.050 --> 00:58.360
Now let's develop a new enemy.

00:58.450 --> 01:01.630
So what we're going to make in this video is this chicken enemy.

01:01.630 --> 01:02.800
We have a great reference.

01:02.800 --> 01:04.360
We can see how does it work.

01:04.360 --> 01:09.400
And it's basically going to run into direction of a player and then stop if it does not see the player

01:09.400 --> 01:10.660
something like that.

01:10.660 --> 01:15.550
Let's go to the unity and let's set up GameObject and animations first.

01:15.550 --> 01:19.240
Uh, actually, before we do that, let's make a prefab out of a mushroom.

01:19.240 --> 01:20.740
We're going to go to prefabs.

01:20.860 --> 01:24.640
I think it's time to hide these traps inside of a folder.

01:24.640 --> 01:26.020
So I'm going to make one.

01:26.020 --> 01:26.890
Traps.

01:27.770 --> 01:29.330
Let's take the traps.

01:29.330 --> 01:30.320
Place them.

01:30.960 --> 01:32.610
Place them into the folder.

01:32.610 --> 01:36.420
Then let's make folder for VFX.

01:36.420 --> 01:39.450
Let's take the particle and players effect.

01:39.450 --> 01:40.410
Place it here.

01:40.410 --> 01:40.920
Cool.

01:40.920 --> 01:47.010
Now we can take the mushroom, make it as a prefab and I think we can move mushroom over here so it

01:47.010 --> 01:48.660
does not bother us much.

01:48.660 --> 01:50.640
Also, I want to change the level a bit.

01:50.640 --> 01:57.270
So I'm going to remove fruits and I want to erase this piece of ground over here because I want to place

01:57.270 --> 01:57.810
a.

01:59.820 --> 02:01.830
Uh, Colin platform.

02:03.150 --> 02:07.350
Like so, because I need a bit more space over here to jump over the enemies.

02:07.380 --> 02:09.150
Okay, this is nice.

02:09.180 --> 02:13.590
Now, maybe these spikes as well don't want to have it there.

02:15.970 --> 02:18.580
Now let's make the enemy new one.

02:18.580 --> 02:22.360
We're going to go to Graphics Enemies chicken.

02:22.360 --> 02:28.090
Let's take this sprites over here and make sure we have pixel per unit 16.

02:29.060 --> 02:29.750
Okay.

02:29.750 --> 02:30.800
That's cool.

02:30.800 --> 02:34.910
Now let's go ahead and make a game object.

02:35.830 --> 02:36.910
This is going to be.

02:37.720 --> 02:38.560
Enemy.

02:39.830 --> 02:41.330
Let's do enemy.

02:42.290 --> 02:43.040
Chicken.

02:43.280 --> 02:47.720
We also need to change layer of the GameObject to the enemy.

02:49.600 --> 02:52.360
Let's go ahead and add animator.

02:54.430 --> 03:00.490
And we need animator controller so we could go ahead and make Animator controller a controller same

03:00.490 --> 03:01.600
way as it was before.

03:01.600 --> 03:05.170
And then I'm going to show you a nice trick to make your work faster.

03:05.170 --> 03:07.660
First of all, let's make a folder for this.

03:07.660 --> 03:09.580
So I'm going to do enemies.

03:09.580 --> 03:12.550
And let's take these things over here.

03:12.550 --> 03:13.990
Drag them to the enemies.

03:13.990 --> 03:17.170
And over here I'm going to make a folder for the mushroom.

03:17.950 --> 03:21.970
Mushroom I'm going to take animations drag them here.

03:21.970 --> 03:24.280
Controller I'll keep outside for now.

03:24.280 --> 03:26.140
Now let's make another one.

03:26.200 --> 03:27.580
Animator controller.

03:27.580 --> 03:29.140
Enemy chicken.

03:29.140 --> 03:29.710
Take.

03:31.310 --> 03:34.760
We can place it on the enemy and drag it here and now.

03:34.760 --> 03:37.010
We can create animation same way as before.

03:37.010 --> 03:38.420
Let's quickly do that.

03:38.420 --> 03:39.920
Let's quickly do that.

03:41.230 --> 03:41.860
All right.

03:41.860 --> 03:42.850
We're going to do.

03:43.900 --> 03:46.660
Uh, enemy chicken idol.

03:47.660 --> 03:50.930
Then I go to graphics of the chicken.

03:52.140 --> 03:53.700
Let's take idle sprites.

03:53.700 --> 03:54.690
Place them here.

03:54.690 --> 03:56.280
Sample rate 20.

03:56.340 --> 03:59.910
Then we're going to need new clip enemy chicken.

03:59.910 --> 04:00.690
Move.

04:01.710 --> 04:04.920
This is the move animation over here.

04:04.920 --> 04:05.460
Boom!

04:05.460 --> 04:11.040
Sample rate 20 and enemy chicken hit.

04:14.570 --> 04:15.380
Okay.

04:16.290 --> 04:17.670
Sample rate 20.

04:18.920 --> 04:25.130
Now, if you go to animator of the chicken, you probably notice that these animations are very similar

04:25.130 --> 04:30.380
to the animations that we had on the mushroom, and it would be very nice to take set up of the mushroom

04:30.380 --> 04:35.870
and just move it to the enemy chicken and somehow replace the animations.

04:35.870 --> 04:39.080
But keep parameters, keep conditions, everything.

04:39.080 --> 04:41.870
And there is a way to do that.

04:41.870 --> 04:49.550
We can go to assets, animations, enemies and over here I'm going to delete this enemy chicken AC.

04:49.790 --> 04:53.000
Let's just delete it and I'm going to make.

04:53.770 --> 04:56.800
New Animator override controller.

04:57.710 --> 05:01.400
Let's name it as Enemy Chicken AC.

05:02.760 --> 05:08.760
And this controller will help you to basically use setup of a mushroom with new animations.

05:08.760 --> 05:12.180
First you want to set up the base over here where it says none.

05:12.180 --> 05:15.570
So we're going to take Enemy mushroom AC and drag it here.

05:15.900 --> 05:18.180
Then we can see default animations.

05:18.180 --> 05:23.670
It says original over here and if you want you can place override for each animation.

05:23.670 --> 05:30.300
So for example we can place heat of the chicken idol of the chicken and move of the chicken.

05:30.300 --> 05:37.290
Thanks to this, now we can select enemy chicken and drag this override controller over here to the

05:37.290 --> 05:38.550
controller field.

05:39.180 --> 05:39.690
POW!

05:39.840 --> 05:44.580
And now chicken has same conditions as mushroom head.

05:45.710 --> 05:48.500
Uh, but and same parameters that mushroom had.

05:48.500 --> 05:50.720
But it's using its own animations.

05:50.720 --> 05:55.580
You can just go here and change the name from enemy mushroom to enemy hit.

05:55.910 --> 05:57.230
Oh, again, this bug.

05:57.230 --> 05:58.100
Can you imagine?

05:58.100 --> 05:59.750
I need to restart unity.

05:59.750 --> 06:00.890
I'm going to do it quick.

06:00.890 --> 06:03.350
So now enemy hit.

06:03.350 --> 06:05.540
Yeah, it's a bit easier to understand now.

06:05.540 --> 06:08.030
And it has same setup of the animations.

06:08.030 --> 06:09.020
Very good.

06:09.020 --> 06:11.060
Now let's set up.

06:11.610 --> 06:12.960
The movement of the chicken.

06:12.960 --> 06:15.510
We just need to have a rigid body on it.

06:15.510 --> 06:16.620
Rigid body 2D.

06:17.100 --> 06:21.030
Let's do interpolate collision detection continuous.

06:21.030 --> 06:24.210
Then we need a box collider 2D.

06:24.360 --> 06:29.610
And I just realized we don't need to adjust the size of the collider according to the damage area of

06:29.610 --> 06:34.440
the enemy, because player does not collide with enemies layer, so you can keep it as it is.

06:34.440 --> 06:43.710
This is good and we can add new empty object damage trigger that would have maybe a capsule collider.

06:43.710 --> 06:45.660
It's very suitable for this enemy.

06:46.470 --> 06:49.380
Let's open this and edit the size.

06:53.750 --> 06:54.200
Yeah.

06:54.200 --> 06:54.740
Like that.

06:54.740 --> 06:55.970
It's okay, I think.

06:56.670 --> 06:57.750
Should be fine.

06:57.900 --> 07:01.020
Let's do is trigger and give it damage trigger.

07:03.240 --> 07:03.990
Nice.

07:03.990 --> 07:09.810
And we need empty object ground check that is going to be used later.

07:09.900 --> 07:12.840
Now we need a script on this game object.

07:13.500 --> 07:17.760
Let's go to scripts and let's make new C sharp script.

07:17.850 --> 07:18.960
Enemy.

07:20.770 --> 07:21.640
Chicken.

07:22.050 --> 07:22.860
Okay.

07:23.830 --> 07:26.080
Very cool anime chicken.

07:26.260 --> 07:28.030
Now for the anime chicken.

07:28.030 --> 07:31.720
It's supposed to behave in a very similar way that mushroom does.

07:31.720 --> 07:36.370
And just to make sure it's working, I'm going to inherit from the enemy like so.

07:36.370 --> 07:39.520
And I'm going to take entire script of the enemy mushroom.

07:40.490 --> 07:42.110
And just paste it in here.

07:44.570 --> 07:47.720
Let me save it and let's go back.

07:50.840 --> 07:52.370
Let's go to play mode.

07:53.900 --> 07:54.290
Oh, sorry.

07:54.290 --> 07:56.180
We need to set up a bunch of things I forgot.

07:56.180 --> 07:58.190
We need to place the script on the object.

07:58.190 --> 07:58.910
We need to give it.

07:58.940 --> 08:00.290
What is ground?

08:00.770 --> 08:03.500
The ground check damage trigger.

08:03.500 --> 08:08.720
And probably we need to increase wall check distance because collider for the chicken is bigger.

08:09.440 --> 08:10.880
I think I can just.

08:11.790 --> 08:14.700
Slightly reduce the size of a collider here.

08:15.000 --> 08:16.140
Other than that.

08:17.530 --> 08:18.640
This is good.

08:20.520 --> 08:21.270
Yeah.

08:21.270 --> 08:27.270
So now we just basically did the same setup as we did for mushroom, but much, much faster because

08:27.270 --> 08:30.360
we have inheritance animator, override controller and so on.

08:30.360 --> 08:32.040
And we can see chicken runs.

08:32.760 --> 08:37.170
Oh, almost as it runs before like a mushroom.

08:37.170 --> 08:38.070
What happened there?

08:38.070 --> 08:39.450
Why she didn't stop.

08:42.050 --> 08:43.520
And when she didn't flip.

08:47.070 --> 08:48.330
Oh, because I know why.

08:48.330 --> 08:50.040
Because I didn't take this brown check.

08:50.040 --> 08:52.800
It did not place it in front of the chicken like so.

08:53.400 --> 08:54.090
Okay.

08:55.260 --> 08:58.800
Let me give it speed over five and test it again.

09:01.470 --> 09:02.940
Very fast enemy.

09:03.860 --> 09:05.240
Runs like a mushroom.

09:05.510 --> 09:06.230
Nice.

09:06.230 --> 09:06.950
Yay!

09:06.980 --> 09:08.120
Now let's improve it.

09:08.120 --> 09:11.210
Let's make it a bit different functionality from the mushroom.

09:11.210 --> 09:13.100
As you've seen on the example.

09:13.100 --> 09:19.100
On the reference, we have chicken stands there and not moving until it detects the player.

09:19.100 --> 09:21.980
Once it's detecting the player, it runs into the player.

09:21.980 --> 09:24.050
And that's what I want to set up in this video.

09:24.050 --> 09:25.490
How can we set up the player?

09:25.490 --> 09:28.910
Well we're going to need an additional, uh, collision.

09:28.910 --> 09:30.530
And I'm going to make a header.

09:31.190 --> 09:32.000
Chicken.

09:32.000 --> 09:33.260
Uh, details.

09:34.200 --> 09:40.230
And it's going to have sterilized field, private float, agro duration.

09:40.230 --> 09:44.850
And we're going to need private float agro timer.

09:44.880 --> 09:45.600
Nice.

09:45.600 --> 09:47.220
We also need sterilized field.

09:47.220 --> 09:48.180
Private.

09:51.150 --> 09:56.040
Private bool player detected and we need serialize field.

09:56.070 --> 09:57.210
Oh, I'm so sorry.

09:58.480 --> 10:00.010
We need private float.

10:00.130 --> 10:00.550
Um.

10:00.640 --> 10:02.830
Detection range.

10:02.830 --> 10:04.420
And we need serialize field.

10:04.420 --> 10:05.770
Private float.

10:06.370 --> 10:07.000
Uh.

10:08.860 --> 10:10.300
Actually, we need layer mask.

10:10.300 --> 10:11.230
Layer mask.

10:11.230 --> 10:13.390
What is player?

10:13.750 --> 10:21.310
Now I assume that what is player will be needed for other enemies as well for different reasons.

10:21.550 --> 10:25.450
And also we're going to need a boolean that says if enemy can move or not.

10:25.450 --> 10:29.140
So I'm going to remove it from here.

10:30.050 --> 10:31.550
Going to go to enemy.

10:32.920 --> 10:36.970
Let me find collision checks over here and I'm going to do.

10:37.630 --> 10:39.130
Serialized field.

10:39.160 --> 10:40.000
Private layer.

10:40.000 --> 10:40.390
Mask.

10:40.390 --> 10:40.780
Sorry.

10:40.780 --> 10:41.560
Protected.

10:41.560 --> 10:42.700
Protected.

10:44.120 --> 10:45.080
Layer mask.

10:45.230 --> 10:47.150
What is player?

10:47.150 --> 10:49.400
Because it's going to be used by many enemies, I'm sure.

10:51.030 --> 10:53.580
And we need a boolean that would say if we can move.

10:53.580 --> 10:59.310
So maybe under the move speed I'm going to do protected bool can move.

11:00.070 --> 11:00.970
Uh, yeah.

11:00.970 --> 11:02.470
Let's make it true by default.

11:02.470 --> 11:03.160
Okay.

11:05.200 --> 11:05.890
Yeah.

11:06.350 --> 11:06.920
Nice.

11:06.920 --> 11:09.920
So we have a boolean can move and we have what is player.

11:09.950 --> 11:12.080
Now let's go back to enemy chicken.

11:12.410 --> 11:13.430
Oh wait a second.

11:13.430 --> 11:17.570
We want to use the gizmos on the chicken with a new gizmo line.

11:17.570 --> 11:24.320
So let's go here and make it as protected virtual void.

11:24.320 --> 11:25.340
Nice.

11:25.490 --> 11:27.440
Now let's go back to enemy chicken.

11:28.420 --> 11:32.080
One of the things I want to do is to override handle collision.

11:32.080 --> 11:35.080
So I'm going to do override handle collision.

11:35.080 --> 11:41.980
And in here we're going to do player detected equals to physics 2D raycast from a transform position

11:41.980 --> 11:43.630
into vector two dot.

11:44.690 --> 11:45.410
Dot right?

11:45.410 --> 11:50.810
Multiply it by facing direction with a detection range.

11:51.020 --> 11:52.910
And what is player layer.

11:52.910 --> 11:54.620
And we need to override.

11:55.650 --> 11:56.640
What is happening?

11:58.840 --> 12:03.040
And we need to override Ondraw gizmos, override on draw gizmos.

12:03.040 --> 12:05.140
And we need gizmo for this line.

12:05.140 --> 12:11.650
For this raycast I'm going to go ahead pick definition and I want to take the third line which does

12:11.650 --> 12:12.640
the wall check.

12:13.920 --> 12:19.290
And instead of using wheelchair distance, I'm going to use detection range.

12:19.290 --> 12:20.940
And I then need to type this again.

12:20.940 --> 12:22.860
I have very similar line of code.

12:22.890 --> 12:23.550
Nice.

12:23.550 --> 12:26.160
So now this will detect the player if we want to.

12:26.280 --> 12:27.360
And.

12:28.420 --> 12:35.170
On the handle movement instead of idle timer we actually want to use can move boolean and if it's a

12:35.170 --> 12:36.520
false then we return.

12:36.520 --> 12:37.750
We do not move.

12:37.840 --> 12:38.890
Super good.

12:38.920 --> 12:42.730
Now when do we make can move true.

12:42.760 --> 12:50.110
Well, in the update we can check if player detected then can move equals to true.

12:50.110 --> 12:55.780
And also it would be a good idea to set timer of the aggression to a positive value once we detect the

12:55.780 --> 12:56.380
player.

12:56.380 --> 12:59.200
So I'm going to do aggro timer.

13:00.320 --> 13:02.420
Equals to aggro duration.

13:02.750 --> 13:05.480
And of course we need to reduce the timer.

13:05.480 --> 13:06.380
So I'm going to do.

13:07.450 --> 13:09.310
Uh, agro timer.

13:11.270 --> 13:13.490
Minus equals times delta time.

13:15.960 --> 13:16.620
All right.

13:16.620 --> 13:17.610
Very good.

13:17.610 --> 13:19.470
So half of the job done.

13:19.530 --> 13:23.130
We have timer of the aggression that is decreasing all the time.

13:23.130 --> 13:28.110
If player detected we say you can move and we enable aggro timer.

13:28.110 --> 13:33.960
Then if aggro timer is less than zero means aggression has passed.

13:33.960 --> 13:36.180
We did not detect player for a while.

13:36.180 --> 13:39.030
And we're just going to do can move equals to false.

13:39.030 --> 13:46.020
So if we did not detect player for a while, if we did not update aggro timer then we stop the movement.

13:46.500 --> 13:48.000
Okay this is good.

13:48.000 --> 13:50.880
Let's go and see what it does now.

13:50.880 --> 13:53.910
Then we're going to improve the functionality on the enemy chicken.

13:53.910 --> 13:58.380
We need to choose what is player, player and agro duration.

13:58.380 --> 14:00.330
Let's set three seconds.

14:02.110 --> 14:04.810
And detection range can be something like 15.

14:08.640 --> 14:09.300
Cool.

14:09.300 --> 14:15.090
I'm going to place this enemy over here, and I'm going to jump in front of her and see if she starts

14:15.090 --> 14:15.840
running.

14:17.600 --> 14:18.650
Uh, chicken stands.

14:18.680 --> 14:19.550
Cool.

14:19.850 --> 14:20.570
Hey.

14:20.570 --> 14:20.990
Okay.

14:20.990 --> 14:22.130
It runs to me.

14:22.130 --> 14:29.900
Then it flips back because it did not see me and stops because aggression duration was over and she's

14:29.900 --> 14:31.070
not aggressive anymore.

14:31.100 --> 14:32.330
Very nice.

14:32.480 --> 14:39.770
Um, I think it's a good idea to switch off the movement and aggression if it did not see the player,

14:39.770 --> 14:43.460
and if it detected the ledge or the wall.

14:43.670 --> 14:45.290
Let's go to enemy chicken.

14:46.920 --> 14:49.710
And handle turnaround over here.

14:49.710 --> 14:51.000
We're going to do this.

14:51.760 --> 14:54.190
We're gonna flip and we're gonna say.

14:55.110 --> 14:55.860
Can move.

14:57.040 --> 14:59.560
And we're going to say can move equals to false.

15:01.770 --> 15:05.430
Also, this chicken does not use idle timers, so I'm going to just remove it.

15:07.040 --> 15:09.320
Okay, let's go ahead and see this.

15:09.320 --> 15:09.830
Now.

15:09.830 --> 15:11.270
How does it behave?

15:15.620 --> 15:16.220
Stands.

15:16.220 --> 15:18.680
They're gonna make me visible.

15:18.680 --> 15:19.040
Okay?

15:19.040 --> 15:23.300
She tries to catch me, sees the ledge, stops and turns around.

15:23.300 --> 15:24.800
Now, if I go back.

15:26.560 --> 15:28.240
And show myself again.

15:28.270 --> 15:29.470
Going to be aggressive.

15:30.410 --> 15:31.940
And we can kill it.

15:32.060 --> 15:34.370
All we need to stop the cycle of the animation.

15:35.280 --> 15:35.610
Cool.

15:35.610 --> 15:37.440
Let's go to asset animation.

15:37.440 --> 15:38.550
Enemies.

15:38.580 --> 15:39.210
Chicken.

15:39.210 --> 15:40.860
Hit loop time and check.

15:41.250 --> 15:47.010
Now, the last thing we need to do is to make it turn into direction of a player.

15:47.010 --> 15:49.170
If player jumps over the chicken.

15:51.240 --> 15:53.130
That's a bit tricky to do.

15:53.220 --> 15:55.230
Uh, let's go back to the script.

15:55.230 --> 16:00.210
And actually, this method is supposed to work like that, but it does not work like that.

16:00.210 --> 16:02.310
We need to adjust the method, I guess.

16:02.310 --> 16:10.020
So over here we need to check x value and compare it not to zero but to the transform position transform

16:10.020 --> 16:12.270
position dot x.

16:13.740 --> 16:14.820
Over here as well.

16:15.670 --> 16:17.770
Transform position dot x.

16:17.770 --> 16:22.150
So now if we pass players position over here it's going to be like that.

16:22.780 --> 16:26.740
Players position less than my x position means player is on the left.

16:26.740 --> 16:29.080
And if I'm facing right I'm going to flip.

16:29.500 --> 16:31.990
Players position is oh sorry.

16:31.990 --> 16:33.070
This one should be.

16:36.910 --> 16:39.940
Instead of zero transform.position.x.

16:39.970 --> 16:40.600
Okay.

16:40.600 --> 16:44.740
And in this side we're going to check player's position is.

16:45.300 --> 16:50.340
Bigger on the X than my position means player is on the right side and I'm facing right?

16:50.370 --> 16:50.910
No?

16:50.910 --> 16:52.020
Then flip.

16:52.020 --> 16:53.640
This is how it's going to work.

16:54.120 --> 16:55.800
Uh, let's go to enemy chicken.

16:58.560 --> 16:59.940
Maybe in the Handal movement.

16:59.940 --> 17:01.050
We can do this.

17:02.660 --> 17:04.460
I'm going to do a handle flip.

17:04.460 --> 17:08.180
And over here we need to pass player's X position.

17:08.180 --> 17:10.580
But we don't have reference to the player yet.

17:10.580 --> 17:13.010
So let's go to enemy script.

17:16.300 --> 17:17.590
This is pretty messy.

17:17.590 --> 17:21.880
I would like to clean it up, but I don't want to spend time on this right now, so we're going to do

17:21.880 --> 17:23.170
it in the end for now.

17:23.170 --> 17:23.890
This is good.

17:23.890 --> 17:24.940
Let's just do it like so.

17:24.940 --> 17:25.540
Maybe.

17:28.270 --> 17:29.680
Couple of spaces.

17:30.200 --> 17:32.390
And here we're going to have serialized field.

17:33.270 --> 17:35.940
Protected transform player.

17:36.480 --> 17:37.380
Nice.

17:37.380 --> 17:39.510
Now we're going to go to the.

17:40.600 --> 17:41.440
Start method.

17:41.440 --> 17:45.670
We cannot do it in their wake, because our wake of the game manager can be called after the wake of

17:45.670 --> 17:48.760
the enemy, and if that's the case, then it will not work.

17:48.760 --> 17:53.470
So let's do protected virtual void start.

17:53.470 --> 17:58.660
And here we're going to do player equals to game manager dot instance dot player.

17:59.390 --> 18:01.160
Dot transform.

18:01.160 --> 18:01.790
Okay.

18:01.790 --> 18:05.810
Also, we need to update this value, uh, when player dies.

18:05.810 --> 18:07.670
But we're going to take care of that later on.

18:07.670 --> 18:13.460
Actually, maybe let's take care of this right now I'm going to do private void update players.

18:14.750 --> 18:19.310
Lazareff as a reference is going to do this.

18:19.460 --> 18:27.890
If player equals to null, then player equals to game manager, dot instance, dot player dot transform.

18:27.980 --> 18:33.620
And we're going to start invoke repeating which will repeat the method.

18:34.300 --> 18:35.470
Name of.

18:38.690 --> 18:40.040
Update players riff.

18:42.580 --> 18:47.620
Let's do it immediately so we have no delay and repeat rate going to be every second.

18:47.620 --> 18:52.030
Let's say we probably can do this better, but as of now this is just perfect.

18:52.030 --> 18:54.700
So now we made a reference to the player.

18:55.870 --> 18:56.950
Over here.

18:56.950 --> 19:00.370
It will be assigned in the method over here.

19:00.370 --> 19:05.350
And if we lose the players reference, if player dies and we respawn a new one, we're going to update

19:05.350 --> 19:06.310
it every second.

19:06.310 --> 19:06.970
Okay.

19:06.970 --> 19:08.560
Let's go back to enemy chicken.

19:08.560 --> 19:14.050
And let's do handle flip with a player position dot x.

19:14.410 --> 19:16.630
Nice I'm going to save this.

19:16.660 --> 19:18.160
Go back to unity.

19:20.950 --> 19:22.540
Let's go to play mode.

19:23.750 --> 19:24.770
A chicken.

19:25.860 --> 19:27.240
Yeah, okay.

19:27.240 --> 19:30.150
It turned back to me, but it was so easy to kill it.

19:30.780 --> 19:32.850
I'm not sure if that's how it's supposed to be.

19:35.580 --> 19:38.010
Yeah, I'm just killing it automatically, man.

19:39.490 --> 19:42.310
How does it work differently on the reference anyway?

19:42.310 --> 19:43.330
Functionality is there.

19:43.330 --> 19:44.320
Works fine.

19:46.500 --> 19:50.550
Just need to think how to make it more fun, because now it's sort of too easy.

19:53.740 --> 19:54.550
And so fun.

19:54.550 --> 19:56.200
She runs behind me, I like it.

19:56.200 --> 19:57.760
Let me see the reference.

20:00.970 --> 20:03.640
Looks the same to me.

20:03.670 --> 20:05.350
Okay, maybe it's supposed to be like that.

20:05.350 --> 20:07.690
Maybe it's supposed to be an easy enemy that runs behind you.

20:07.690 --> 20:09.550
So who am I to judge?

20:09.910 --> 20:13.300
The functionality feels pretty fun, and it was really interesting to make.

20:15.400 --> 20:19.150
Um, we don't need to do really anything here.

20:19.150 --> 20:20.830
And we could not use inheritance.

20:20.830 --> 20:21.040
Really?

20:21.040 --> 20:26.080
Because these methods haven't a bit different functionality from the enemy mushroom, right?

20:26.080 --> 20:27.010
They are slightly different.

20:27.010 --> 20:30.580
So it's okay to keep them like that private.

20:32.190 --> 20:36.630
Maybe later on I'm gonna move this to the, like, some sort of animator.

20:36.630 --> 20:39.060
But later on, as of now, this is good.

20:39.300 --> 20:42.030
I don't think we need anything else for now.

20:43.830 --> 20:47.730
I only would like to clean up this mess over here.

20:47.760 --> 20:48.390
Give me a second.

20:48.390 --> 20:49.740
I'll see what I can do.

20:49.770 --> 20:51.330
Now we can just make a header.

20:52.260 --> 20:53.250
Let's do header.

20:54.060 --> 20:54.900
General.

20:55.170 --> 20:56.010
Um, info.

20:56.040 --> 20:57.330
Okay, I'm going to save it.

20:57.330 --> 21:04.470
Go back to unity and we have a new enemy that is clean nice as some specific details.

21:04.470 --> 21:06.480
This boolean can be hidden by the way.

21:10.290 --> 21:12.090
Uh, layer detected.

21:12.450 --> 21:13.080
Hello, guys.

21:13.080 --> 21:18.840
I was just editing the video and I noticed what is the difference between reference and the result we

21:18.840 --> 21:19.350
have.

21:19.350 --> 21:23.220
And on the reference, we can see that chicken flips with a bit of a delay.

21:23.220 --> 21:25.800
And that's what we're going to do now real quick.

21:25.800 --> 21:27.270
It's not that difficult to do.

21:27.300 --> 21:30.870
We need to make a private boolean can flip.

21:30.870 --> 21:33.330
Let's make it equals to true by default.

21:35.700 --> 21:38.070
Then we're going to go to this handle movement.

21:38.070 --> 21:42.300
And over here we're going to pick definition of a handle flip.

21:42.300 --> 21:49.500
And over here we can see I mean we can take this line of code that we use for comparing and the position

21:49.500 --> 21:52.110
and x value.

21:52.110 --> 21:53.880
We just need this line of code.

21:53.880 --> 21:56.340
Now let's go here and paste this line.

21:56.550 --> 21:57.900
Open curly brackets.

21:57.900 --> 22:00.720
And for the x value we need position of the player.

22:00.720 --> 22:02.340
So I'm going to do float.

22:03.820 --> 22:07.150
X value equals to player transform position.

22:07.980 --> 22:09.540
All right, dot x.

22:10.050 --> 22:10.860
Good.

22:10.860 --> 22:15.480
Now, inside of this, uh, curly brackets, we're going to check if can flip.

22:15.480 --> 22:18.210
Then we're going to do can flip equals to false.

22:18.210 --> 22:20.160
So this can be done only once.

22:20.160 --> 22:22.110
And then we're going to invoke.

22:22.910 --> 22:24.110
Name of.

22:25.160 --> 22:29.960
Clip with a delay of maybe 0.3 F, something like that.

22:32.390 --> 22:34.460
Now we need to override the flip.

22:34.460 --> 22:40.370
Override flip because we want to make flip available again once we did the flip.

22:40.370 --> 22:43.310
So we're going to do can flip equals to true.

22:46.910 --> 22:47.510
All right.

22:47.510 --> 22:48.920
And this is it.

22:48.950 --> 22:50.270
We don't need anything else.

22:50.270 --> 22:56.030
If you want, we can make it sort of cleaner by overriding, uh, handle flip method.

23:01.200 --> 23:05.430
Then we could take these things over here.

23:05.820 --> 23:08.730
Actually, just these things over here.

23:08.970 --> 23:12.150
Remove the base and paste new functionality in.

23:12.600 --> 23:13.680
Just like so.

23:13.680 --> 23:21.300
And then over here we're going to just handle flip with a layer transform position dot x.

23:21.300 --> 23:22.470
And we do need this.

23:22.470 --> 23:22.800
Yeah.

23:22.800 --> 23:26.490
This makes it sort of cleaner I guess because we overwritten the method.

23:26.490 --> 23:28.200
Now it has different functionality.

23:28.200 --> 23:31.050
And now we can go back to unity and check this.

23:31.470 --> 23:33.450
I only want to take the chicken itself.

23:33.450 --> 23:36.420
And I want to reduce the size of the collider.

23:36.420 --> 23:41.580
So it's not so easy to kill the chicken because when player detecting the enemy he checks the collider.

23:41.580 --> 23:42.420
It has.

23:42.420 --> 23:46.590
In this case it's this box collider which is quite easy to detect.

23:47.970 --> 23:52.590
So maybe we can take it and reduce the height of it to something like so.

23:52.770 --> 23:56.070
Well, let's try, uh, maybe later we're going to fix it.

23:56.070 --> 24:00.150
And also for the damage trigger, I'm going to replace it with a box collider.

24:01.350 --> 24:06.180
Let me just take and copy a component from here and go to the image trigger.

24:07.590 --> 24:12.330
Based component is new, I'm going to slightly reduce it on the Y.

24:13.080 --> 24:14.340
Check is trigger.

24:14.370 --> 24:20.430
Then I'm going to do override apply all and let's go ahead test it quickly and we can move on to next

24:20.430 --> 24:21.060
video.

24:24.430 --> 24:26.290
Yeah, now it's good works.

24:26.290 --> 24:28.330
Same as on the reference.

24:28.330 --> 24:29.770
And it's not so easy to kill.

24:29.770 --> 24:31.630
You actually need to bump on the head.

24:32.290 --> 24:33.040
Okay.
