Hello guys.
Welcome to the video.
In this one I want to show you how to make another enemy.
This time it's going to be a blue bird.
And probably it's going to be the last enemy we're going to make in this course.
I want to show you this one, just to give you an example on how you could mix the movement from a transform
like a vector to move towards and rigid bodies velocity.
It's a very suitable example to give, because you can see how you can mix those movements when you
need some special behavior from the enemy.
And let's go to.
Asset.
Prefabs.
Enemies.
Uh, sorry.
We need graphics.
Enemies.
Bluebird, make sure you have this with a pixel per unit 16 over here.
And then, uh, maybe I can do prefab unpack completely for the reddish.
Make sure you have it as a prefab, then unpack it.
We don't need gunpoint for this and we don't need this script.
And on sprite renderer, we can just take the flint sprite of the bird.
Okay, let's adjust collider.
Hmm.
Something like this should work.
Yeah, but the damage trigger.
I'm going to move it.
Here like that.
Some reason it's not in the center.
So I'm going to remove offset and do like that okay.
Nice.
Now we need a script on this.
And animator.
Let's go to asset animations.
Enemies.
We're going to make a folder.
Bluebird.
Inside.
We need animator.
Enemy.
Blue bird.
AC.
Let's put it on a bird over here.
And let's create a clip.
It's not many this time, so we're just going to do enemy Blue Bird Fly.
Let's go to graphics.
Enemies.
Bluebird.
We're going to take flying animation.
Sample rate 20.
And we need one more enemy.
Blue bird hit.
We're going to take hit sprite.
Drag them here.
Sample rate 20.
Okay, let's go to animator of this bird and we're going to need one trigger hit.
We're going to transfer to Bluebird hit.
We can do it from anywhere because we have only two animations with the trigger.
Hit exit time.
Uncheck transition duration zero okay.
And this is ready.
Let's go to Asset Scripts enemies and let's make.
Enemy Blue Bird.
Actually for Bluebird, we don't need to do inheritance from any script because none of these things
is going to be used on the bird, I guess.
But there are some things like.
Animator component and colliders and so on.
As since we're doing it like that, I guess.
Yeah, let's let's do inheritance, even though we're not going to use most of the things, it will
be faster and easier this way.
Now let's make a header.
Blue bird details.
And over here I want to have a serialized field private float travel distance.
And let's make it equals to eight by default.
So travel distance is going to define how bird is going to fly.
It will help us to set up movement of the bird in a very easy way.
Here is the bird.
And if we have travel distance of eight it means it's going to move like this is the travel distance
and minus four to the left, plus four to the right.
And it's going to just, uh, have a distance of eight in total.
So that's what I want to have for the movement of the bird.
Now let's make a waypoints.
I'm going to make them a serialized field so you can see how it works.
Let's do private Vector3 array waypoints equals to a new Vector3 of.
And let's not do new.
It's okay.
We can do it in the inspector.
And let's do private int way index.
This is going to be very similar to the movement of the b.
But uh, just wait a bit because I'm going to show you how different it is okay.
Let's do waypoint.
Uh, with a zero.
Is equals to new Vector3 Transform.position minus travel distance divided by two.
So only half of the travel distance.
It should be dot x and then transform position dot y.
Then we need same for the right side.
So I'm going to do plus over here and waypoint one.
Then let's take away index and make it equals to random range from zero to waypoint length.
So it's going to choose a random direction at the start.
And then let's set up um.
Movement itself.
Overwrite.
Update.
Handle movement.
Nothing that we didn't do before.
Sorry.
That was my friend who made a sound.
And then.
We need to make something very simple.
If can move.
False.
Then we return and then transform position.
Equals to vector two.
Move towards from transform.position to waypoint with away index, and as a speed we're going to use
move speed multiplied by time dot delta time, same as before.
Then we need to adjust the index.
So if we are to the distance between transform.position and yeah, there's going to be the last time
we type in this I promise because I'm kind of tired of it as well.
Uh, maybe you're not.
I am a little bit tired of using this statement.
What did I do wrong here?
It should be waypoints with array index.
Okay.
Then we index plus plus.
And if we index is yes then we index is yes okay.
This is what we should have.
So this will make it move.
Although we're not going to see how it moves.
Let's do a handle flip into waypoint with away index.
Dot x.
Okay, uh, let's see how it moves left and right.
But we're not going to see the distance until it flies.
That is not very good for us.
So I'm going to show you how to make.
Uh, set up easier.
But for now, let's just be sure it is working.
I'm gonna give it, uh.
Let's do gravity scale zero for now.
Just for now.
Keep rigid body dynamic and let's do Bluebird script travel distance eight waypoints two.
Let's make lengths of 8.2 and let's go.
It does not fly.
Uh, something is wrong, I believe.
Oh, yes.
Okay.
We need to assign variables.
Let's drag ground check.
Layer ground.
This can be zero.
This can be zero and this can be zero.
And also we need to change it to.
Uh, flying enemy?
No, this object only.
Okay, let's go and see this again.
So there is a bird moves left and right.
It's pretty much okay.
And it works just like that.
Although I would like to make it a bit more realistic, I want to make it heavy, so it's gonna pull
while it flies.
And then with each flap of wings, we're going to push it up a little bit.
That's what I want to do.
And also I want to make gizmos so I can see the waypoints it's going to use.
So let's go to enemy Blue Bird.
Now let's make a sterilized field.
Private float lifeforce.
I'm going to make it equals to 1.5 by default.
And then we're going to make a method.
Pilot would fly up.
We're going to do something very simple.
RB velocity equals to new vector two.
RB velocity dot x and fly up fly force.
Okay.
We're going to use this method later.
Now let's make gizmos so we can see how things are working.
And we're going to need a private ball in play mode, which we're going to set to true in the start
in play mode equals to true.
We need this because we want to draw gizmos to the same position, but we cannot do it inside of on
draw gizmos because on draw gizmos is called inside of the editor and start is not.
So these variables would be empty.
And because of that.
We need to make new variables inside of Android gizmos and then stop using them if we are in the play
mode.
Also, let's do a.
Equals to new vector two with a size of two.
So now we can hide it.
And we don't need to see it because we know it is working.
And we did see difference in the position on the x.
Okay, let's go and override Ondraw gizmos.
And this is going to be the last thing we need to do for the bird and draw gizmos.
Um, sorry.
We need to do override Ondraw gizmos and then.
If in play mode is false, then float distance equals to a travel distance divided by two.
Then we're going to do vector three.
Left position equals to new Vector3 from transform position dot x minus distance transform position
dot y and we want to duplicate it.
Do it as a right position.
Lines, distance and gizmos.
We're going to draw a line between them and we're going to do, um, a small sphere so we can see it
as well.
Gizmos.
Draw wire sphere at left position with a 0.5 F, and then right position with a 0.5 F.
And then let's do else.
And inside we can just duplicate this.
Like that.
And.
Uh, actually, I'm sorry.
We don't need this because we can use transform position.
To the, uh, waypoint with a zero and then transform position to the waypoint of one.
So it's going to draw from a bird to the waypoints.
It's going to be connected.
And then over here we can do waypoints zero and waypoints one.
All right, let's save this.
And we have fly up method.
Which is over here.
Now we can go back to unity.
Let's go to project asset Animations enemies Bluebird.
For the heat we need to uncheck loop time.
Then we need to go to Animation Find.
Uh.
Lie.
And let's find the sprite where it flaps the wings.
And it happens over here.
So over here it should gain a velocity.
Let's add event and do methods fly up.
Uh, yeah, just like that.
It's going to be nice.
Now let's go to this object.
Also, it should be renamed to Enemy Bluebird.
And yeah, I forgot to mention, now we can see gizmos, how it should fly from left to right.
And we can make it heavy on the rigid body.
Let's give it gravity scale of one, for example, and fly force 1.5.
So it should be good.
Let's go and try this.
Let's see it.
Now you can see Byrd is heavy is going down.
And with the flap of wings it's going up and it looks a bit more realistic.
If you want you can add fly force.
Now it's not that heavy.
So maybe you should increase the gravity scale.
Yeah, this also could exist.
Why not?
So this is the idea.
This is the bird I want to have.
I kind of like how it works.
Uh, it feels like it's heavy and it feels like it's really flying only when it flaps the wings.
Okay, I'm going to do gravity scale two fly force.
I'm going to do, um.
Maybe three.
Let me keep it like that for now.
And that's it.
Let's go to asset prefabs.
Enemies.
Let's make it as a prefab.
And also before I forgot.
Let's go to the script.
Let's override animator and let's keep it empty like that.
All right.
Thank you so much for paying attention.
And I'll see you in the next video.