WEBVTT

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

00:00.530 --> 00:01.550
Welcome to the video.

00:01.550 --> 00:04.790
In this one I want to show you how to make another enemy.

00:04.790 --> 00:06.860
This time it's going to be a blue bird.

00:06.860 --> 00:10.160
And probably it's going to be the last enemy we're going to make in this course.

00:10.160 --> 00:16.130
I want to show you this one, just to give you an example on how you could mix the movement from a transform

00:16.130 --> 00:19.850
like a vector to move towards and rigid bodies velocity.

00:19.850 --> 00:24.230
It's a very suitable example to give, because you can see how you can mix those movements when you

00:24.230 --> 00:27.170
need some special behavior from the enemy.

00:27.170 --> 00:28.610
And let's go to.

00:29.850 --> 00:30.510
Asset.

00:30.510 --> 00:31.500
Prefabs.

00:31.500 --> 00:32.670
Enemies.

00:33.580 --> 00:35.080
Uh, sorry.

00:35.080 --> 00:36.190
We need graphics.

00:36.190 --> 00:37.120
Enemies.

00:37.600 --> 00:42.670
Bluebird, make sure you have this with a pixel per unit 16 over here.

00:42.760 --> 00:47.590
And then, uh, maybe I can do prefab unpack completely for the reddish.

00:47.590 --> 00:51.160
Make sure you have it as a prefab, then unpack it.

00:52.250 --> 00:56.330
We don't need gunpoint for this and we don't need this script.

00:56.330 --> 01:00.500
And on sprite renderer, we can just take the flint sprite of the bird.

01:01.130 --> 01:03.740
Okay, let's adjust collider.

01:06.210 --> 01:06.510
Hmm.

01:06.510 --> 01:08.400
Something like this should work.

01:10.570 --> 01:12.730
Yeah, but the damage trigger.

01:12.730 --> 01:14.110
I'm going to move it.

01:16.290 --> 01:17.880
Here like that.

01:18.300 --> 01:19.830
Some reason it's not in the center.

01:19.830 --> 01:23.160
So I'm going to remove offset and do like that okay.

01:24.510 --> 01:25.170
Nice.

01:26.510 --> 01:27.920
Now we need a script on this.

01:27.920 --> 01:29.210
And animator.

01:29.210 --> 01:31.640
Let's go to asset animations.

01:31.640 --> 01:32.600
Enemies.

01:37.890 --> 01:38.700
Enemies.

01:38.730 --> 01:40.290
We're going to make a folder.

01:42.350 --> 01:43.730
Bluebird.

01:44.430 --> 01:45.030
Inside.

01:45.030 --> 01:46.560
We need animator.

01:48.750 --> 01:49.680
Enemy.

01:49.890 --> 01:51.870
Blue bird.

01:51.900 --> 01:52.470
AC.

01:53.160 --> 01:55.980
Let's put it on a bird over here.

01:57.980 --> 01:59.600
And let's create a clip.

01:59.840 --> 02:05.240
It's not many this time, so we're just going to do enemy Blue Bird Fly.

02:05.390 --> 02:07.160
Let's go to graphics.

02:08.030 --> 02:08.990
Enemies.

02:08.990 --> 02:09.740
Bluebird.

02:09.740 --> 02:12.170
We're going to take flying animation.

02:12.170 --> 02:14.120
Sample rate 20.

02:14.600 --> 02:16.910
And we need one more enemy.

02:16.910 --> 02:19.310
Blue bird hit.

02:20.230 --> 02:21.460
We're going to take hit sprite.

02:21.460 --> 02:22.480
Drag them here.

02:22.480 --> 02:24.100
Sample rate 20.

02:25.340 --> 02:31.820
Okay, let's go to animator of this bird and we're going to need one trigger hit.

02:32.420 --> 02:34.460
We're going to transfer to Bluebird hit.

02:34.460 --> 02:38.720
We can do it from anywhere because we have only two animations with the trigger.

02:38.720 --> 02:39.800
Hit exit time.

02:39.800 --> 02:42.920
Uncheck transition duration zero okay.

02:43.400 --> 02:44.810
And this is ready.

02:44.810 --> 02:49.250
Let's go to Asset Scripts enemies and let's make.

02:50.800 --> 02:53.290
Enemy Blue Bird.

02:57.150 --> 03:04.770
Actually for Bluebird, we don't need to do inheritance from any script because none of these things

03:04.770 --> 03:07.620
is going to be used on the bird, I guess.

03:07.620 --> 03:09.780
But there are some things like.

03:11.210 --> 03:15.020
Animator component and colliders and so on.

03:15.020 --> 03:17.360
As since we're doing it like that, I guess.

03:17.360 --> 03:22.310
Yeah, let's let's do inheritance, even though we're not going to use most of the things, it will

03:22.310 --> 03:24.200
be faster and easier this way.

03:24.230 --> 03:26.060
Now let's make a header.

03:26.570 --> 03:29.840
Blue bird details.

03:29.840 --> 03:36.650
And over here I want to have a serialized field private float travel distance.

03:36.650 --> 03:39.200
And let's make it equals to eight by default.

03:39.560 --> 03:42.800
So travel distance is going to define how bird is going to fly.

03:42.800 --> 03:46.370
It will help us to set up movement of the bird in a very easy way.

03:46.460 --> 03:47.570
Here is the bird.

03:47.750 --> 03:53.690
And if we have travel distance of eight it means it's going to move like this is the travel distance

03:53.690 --> 03:56.480
and minus four to the left, plus four to the right.

03:56.480 --> 04:00.680
And it's going to just, uh, have a distance of eight in total.

04:00.680 --> 04:03.200
So that's what I want to have for the movement of the bird.

04:03.470 --> 04:05.540
Now let's make a waypoints.

04:05.540 --> 04:08.810
I'm going to make them a serialized field so you can see how it works.

04:08.810 --> 04:14.900
Let's do private Vector3 array waypoints equals to a new Vector3 of.

04:14.900 --> 04:16.010
And let's not do new.

04:16.010 --> 04:16.370
It's okay.

04:16.370 --> 04:17.990
We can do it in the inspector.

04:17.990 --> 04:21.260
And let's do private int way index.

04:21.260 --> 04:23.870
This is going to be very similar to the movement of the b.

04:24.020 --> 04:29.180
But uh, just wait a bit because I'm going to show you how different it is okay.

04:29.360 --> 04:30.770
Let's do waypoint.

04:32.220 --> 04:34.110
Uh, with a zero.

04:34.950 --> 04:42.870
Is equals to new Vector3 Transform.position minus travel distance divided by two.

04:42.900 --> 04:44.970
So only half of the travel distance.

04:46.030 --> 04:51.160
It should be dot x and then transform position dot y.

04:51.610 --> 04:54.220
Then we need same for the right side.

04:54.220 --> 04:58.060
So I'm going to do plus over here and waypoint one.

04:58.270 --> 05:04.990
Then let's take away index and make it equals to random range from zero to waypoint length.

05:04.990 --> 05:07.720
So it's going to choose a random direction at the start.

05:08.290 --> 05:10.060
And then let's set up um.

05:11.710 --> 05:12.880
Movement itself.

05:12.880 --> 05:13.360
Overwrite.

05:13.360 --> 05:14.260
Update.

05:15.470 --> 05:17.600
Handle movement.

05:17.630 --> 05:19.520
Nothing that we didn't do before.

05:20.760 --> 05:21.270
Sorry.

05:21.270 --> 05:24.720
That was my friend who made a sound.

05:24.720 --> 05:25.740
And then.

05:28.250 --> 05:30.260
We need to make something very simple.

05:30.260 --> 05:31.790
If can move.

05:32.430 --> 05:33.210
False.

05:33.690 --> 05:37.530
Then we return and then transform position.

05:41.550 --> 05:42.630
Equals to vector two.

05:42.630 --> 05:49.950
Move towards from transform.position to waypoint with away index, and as a speed we're going to use

05:49.950 --> 05:53.880
move speed multiplied by time dot delta time, same as before.

05:54.610 --> 05:56.320
Then we need to adjust the index.

05:56.320 --> 06:03.010
So if we are to the distance between transform.position and yeah, there's going to be the last time

06:03.010 --> 06:06.580
we type in this I promise because I'm kind of tired of it as well.

06:06.940 --> 06:08.440
Uh, maybe you're not.

06:08.440 --> 06:13.210
I am a little bit tired of using this statement.

06:14.750 --> 06:16.220
What did I do wrong here?

06:16.340 --> 06:18.680
It should be waypoints with array index.

06:22.330 --> 06:23.200
Okay.

06:23.200 --> 06:25.060
Then we index plus plus.

06:25.060 --> 06:31.060
And if we index is yes then we index is yes okay.

06:31.060 --> 06:32.260
This is what we should have.

06:33.110 --> 06:34.670
So this will make it move.

06:35.340 --> 06:37.410
Although we're not going to see how it moves.

06:37.410 --> 06:42.540
Let's do a handle flip into waypoint with away index.

06:44.300 --> 06:45.200
Dot x.

06:46.520 --> 06:50.060
Okay, uh, let's see how it moves left and right.

06:50.060 --> 06:53.660
But we're not going to see the distance until it flies.

06:53.660 --> 06:55.190
That is not very good for us.

06:55.190 --> 06:56.810
So I'm going to show you how to make.

06:57.790 --> 06:59.260
Uh, set up easier.

06:59.260 --> 07:02.200
But for now, let's just be sure it is working.

07:02.470 --> 07:03.880
I'm gonna give it, uh.

07:05.940 --> 07:07.830
Let's do gravity scale zero for now.

07:07.830 --> 07:08.790
Just for now.

07:08.790 --> 07:15.660
Keep rigid body dynamic and let's do Bluebird script travel distance eight waypoints two.

07:15.660 --> 07:19.140
Let's make lengths of 8.2 and let's go.

07:22.980 --> 07:24.090
It does not fly.

07:27.410 --> 07:29.060
Uh, something is wrong, I believe.

07:29.790 --> 07:30.270
Oh, yes.

07:30.270 --> 07:30.660
Okay.

07:30.660 --> 07:32.220
We need to assign variables.

07:32.670 --> 07:34.890
Let's drag ground check.

07:36.340 --> 07:37.450
Layer ground.

07:37.450 --> 07:38.590
This can be zero.

07:38.620 --> 07:40.570
This can be zero and this can be zero.

07:40.570 --> 07:42.460
And also we need to change it to.

07:43.910 --> 07:44.870
Uh, flying enemy?

07:44.870 --> 07:46.430
No, this object only.

07:47.030 --> 07:49.520
Okay, let's go and see this again.

07:51.600 --> 07:54.390
So there is a bird moves left and right.

07:54.390 --> 07:55.680
It's pretty much okay.

07:55.680 --> 07:57.270
And it works just like that.

07:57.270 --> 08:03.810
Although I would like to make it a bit more realistic, I want to make it heavy, so it's gonna pull

08:03.810 --> 08:05.040
while it flies.

08:05.040 --> 08:10.110
And then with each flap of wings, we're going to push it up a little bit.

08:10.620 --> 08:11.670
That's what I want to do.

08:11.670 --> 08:17.160
And also I want to make gizmos so I can see the waypoints it's going to use.

08:17.160 --> 08:19.740
So let's go to enemy Blue Bird.

08:21.410 --> 08:23.810
Now let's make a sterilized field.

08:23.810 --> 08:26.600
Private float lifeforce.

08:26.600 --> 08:29.450
I'm going to make it equals to 1.5 by default.

08:30.090 --> 08:33.360
And then we're going to make a method.

08:34.230 --> 08:36.630
Pilot would fly up.

08:37.390 --> 08:39.130
We're going to do something very simple.

08:39.160 --> 08:41.740
RB velocity equals to new vector two.

08:42.430 --> 08:46.630
RB velocity dot x and fly up fly force.

08:46.660 --> 08:47.380
Okay.

08:48.880 --> 08:50.620
We're going to use this method later.

08:50.620 --> 08:54.790
Now let's make gizmos so we can see how things are working.

08:56.610 --> 09:03.450
And we're going to need a private ball in play mode, which we're going to set to true in the start

09:03.450 --> 09:05.190
in play mode equals to true.

09:05.220 --> 09:10.320
We need this because we want to draw gizmos to the same position, but we cannot do it inside of on

09:10.320 --> 09:15.630
draw gizmos because on draw gizmos is called inside of the editor and start is not.

09:15.630 --> 09:18.000
So these variables would be empty.

09:18.210 --> 09:19.500
And because of that.

09:20.380 --> 09:26.380
We need to make new variables inside of Android gizmos and then stop using them if we are in the play

09:26.380 --> 09:26.860
mode.

09:26.890 --> 09:28.750
Also, let's do a.

09:30.870 --> 09:33.300
Equals to new vector two with a size of two.

09:33.330 --> 09:34.890
So now we can hide it.

09:34.890 --> 09:37.620
And we don't need to see it because we know it is working.

09:37.620 --> 09:40.920
And we did see difference in the position on the x.

09:43.490 --> 09:45.980
Okay, let's go and override Ondraw gizmos.

09:45.980 --> 09:49.730
And this is going to be the last thing we need to do for the bird and draw gizmos.

09:52.200 --> 09:53.460
Um, sorry.

09:53.460 --> 09:57.300
We need to do override Ondraw gizmos and then.

09:58.020 --> 10:05.820
If in play mode is false, then float distance equals to a travel distance divided by two.

10:08.800 --> 10:10.690
Then we're going to do vector three.

10:12.050 --> 10:21.920
Left position equals to new Vector3 from transform position dot x minus distance transform position

10:21.920 --> 10:24.980
dot y and we want to duplicate it.

10:26.760 --> 10:31.020
Do it as a right position.

10:32.200 --> 10:34.600
Lines, distance and gizmos.

10:34.600 --> 10:41.260
We're going to draw a line between them and we're going to do, um, a small sphere so we can see it

10:41.260 --> 10:41.950
as well.

10:42.340 --> 10:43.210
Gizmos.

10:44.180 --> 10:53.060
Draw wire sphere at left position with a 0.5 F, and then right position with a 0.5 F.

10:55.880 --> 10:57.740
And then let's do else.

10:57.740 --> 11:02.540
And inside we can just duplicate this.

11:05.490 --> 11:06.540
Like that.

11:07.190 --> 11:08.060
And.

11:08.770 --> 11:11.440
Uh, actually, I'm sorry.

11:11.440 --> 11:17.350
We don't need this because we can use transform position.

11:18.210 --> 11:25.230
To the, uh, waypoint with a zero and then transform position to the waypoint of one.

11:25.230 --> 11:28.380
So it's going to draw from a bird to the waypoints.

11:28.380 --> 11:29.670
It's going to be connected.

11:31.610 --> 11:36.950
And then over here we can do waypoints zero and waypoints one.

11:40.140 --> 11:42.480
All right, let's save this.

11:42.480 --> 11:44.430
And we have fly up method.

11:45.690 --> 11:47.010
Which is over here.

11:47.010 --> 11:48.900
Now we can go back to unity.

11:50.300 --> 11:55.160
Let's go to project asset Animations enemies Bluebird.

11:55.700 --> 11:57.830
For the heat we need to uncheck loop time.

11:57.830 --> 12:00.680
Then we need to go to Animation Find.

12:00.890 --> 12:01.250
Uh.

12:03.460 --> 12:04.060
Lie.

12:04.060 --> 12:06.880
And let's find the sprite where it flaps the wings.

12:06.880 --> 12:09.430
And it happens over here.

12:09.790 --> 12:12.040
So over here it should gain a velocity.

12:12.040 --> 12:15.850
Let's add event and do methods fly up.

12:17.670 --> 12:18.810
Uh, yeah, just like that.

12:18.810 --> 12:20.010
It's going to be nice.

12:20.010 --> 12:22.500
Now let's go to this object.

12:22.500 --> 12:25.050
Also, it should be renamed to Enemy Bluebird.

12:27.450 --> 12:32.280
And yeah, I forgot to mention, now we can see gizmos, how it should fly from left to right.

12:32.460 --> 12:35.040
And we can make it heavy on the rigid body.

12:35.040 --> 12:40.680
Let's give it gravity scale of one, for example, and fly force 1.5.

12:40.680 --> 12:41.490
So it should be good.

12:41.490 --> 12:43.080
Let's go and try this.

12:43.080 --> 12:43.980
Let's see it.

12:45.790 --> 12:48.910
Now you can see Byrd is heavy is going down.

12:48.910 --> 12:53.800
And with the flap of wings it's going up and it looks a bit more realistic.

12:53.800 --> 12:56.200
If you want you can add fly force.

12:58.460 --> 13:00.080
Now it's not that heavy.

13:00.080 --> 13:03.080
So maybe you should increase the gravity scale.

13:04.450 --> 13:06.610
Yeah, this also could exist.

13:07.140 --> 13:08.100
Why not?

13:10.390 --> 13:11.560
So this is the idea.

13:11.560 --> 13:13.150
This is the bird I want to have.

13:13.150 --> 13:15.100
I kind of like how it works.

13:15.460 --> 13:20.110
Uh, it feels like it's heavy and it feels like it's really flying only when it flaps the wings.

13:20.230 --> 13:23.590
Okay, I'm going to do gravity scale two fly force.

13:23.590 --> 13:25.360
I'm going to do, um.

13:26.560 --> 13:27.370
Maybe three.

13:27.370 --> 13:28.900
Let me keep it like that for now.

13:29.230 --> 13:30.040
And that's it.

13:30.040 --> 13:32.260
Let's go to asset prefabs.

13:32.350 --> 13:33.100
Enemies.

13:33.100 --> 13:35.080
Let's make it as a prefab.

13:36.090 --> 13:38.280
And also before I forgot.

13:38.280 --> 13:40.080
Let's go to the script.

13:43.380 --> 13:47.670
Let's override animator and let's keep it empty like that.

13:48.150 --> 13:49.170
All right.

13:49.290 --> 13:51.090
Thank you so much for paying attention.

13:51.090 --> 13:52.950
And I'll see you in the next video.
