Welcome back my fellow game developers
to a brand new video.
And in this one, if I maximize on
play to see everything when I run the game,
you'll notice that the boss appeal
from the ground and starts walking towards us.
And when he gets to a certain position,
he starts collaborating us clobbering.
Is that even a proper verb?
He starts clobbering us with his giant salt.
So that's not waste any more time.
And let's get started.
Oh, okay, So now let's make the enemy actually
walk or not enemy the boss actually
start walking Towards the player.
So how are we going to do this?
If we go to the animator,
first thing we want to do is we want to transition
from the appear to the actual walking.
So I'm going to create a transition into the walking.
And there is going to be no condition.
There is only going to be an exit time and
maybe a transition duration that see how that looks.
So the enemy appears and there you go.
You can see that when he finishes appearing,
he then transitions into the walking.
You can play around in here.
So for example, let's increase
the exit time to 97 percent.
So we've finished his appearing completely.
Let's see how that looks.
Okay, so there is kind of an error here.
And I want to do all of this in front of you
just so you can see how things happen.
Maybe it will take a bit of time more from the video,
but I have to show you this.
I don't want any confusion anyways.
Now that we have the walking,
it's actually time to first of all,
find the transform of the player,
get a rigid body,
find the direction, and so on, add the velocity.
How are we going to do this?
Well, as you know,
we have all of these states setup right here.
So what I'm going to do,
I'm going to click on the walking.
And you can see right here that I can
add something called a behavior.
So let's click on Add behavior.
Let's go ahead and create a new script.
And instead of boss getting angry for some reason,
we are going to call this the boss walk.
So adding a behavior script to a state
has a different type of
naming convention I'm going to use.
Actually MY unit uses the underscore,
so I'm going to keep with that standard, let's say.
So create an ad,
wait for the file to be imported.
And there we go. Now we have the post-war.
If we click on and see where that actually is,
there we go In the assets.
It's immediately in the assets.
So if any day now,
if I make this a bit bigger so
we can properly see the folders.
And you can see that it's just on the assets.
And for that reason, I'm going to
go into the scripts in here,
right-click and create a new folder
for the boss or boss system.
Let's call it the POS system.
Hit Enter and then backend the assets.
Will drag this into the boss. There we go.
And the boss click on walking.
Is the script still there?
So the new version of Unity is extremely valid anyways,
hopefully yours doesn't take so long
to compile and understand everything.
So now let's double-click on
the boardwalk and let's see what we have in here.
As you can see, we don't have a mono behavior anymore.
As you can see right here,
Mano behavior is usually reserved to
a script that will be attached to a game object.
So something that will move.
For example, in here,
we don't have a motor behavior,
we have a state machine behavior.
And this is a script that is
attached only to certain states.
So Let's continue one,
what do we have here?
Just like we have the start and
update on the mono behavior,
we have the on-state Enter and the on-state update.
We also have the on-state exit,
on-state move and the on-state IQ, whatever that is.
Anyways, we will not be focusing on the last two,
so we can go ahead and delete them.
And in here, I'm going to select
all of these lines because they are commented out.
And we can uncomment
everything using the control shift or not,
sorry, Control K, you.
There we go.
So make sure that to hold down
Control and press K you at the same time.
As you can see, we have a lot of errors.
And that's because these lines are actually the comments.
So just like in here we have over the update,
the comment update is called
every frame you can see in here,
on-state enter is called when a transition starts,
and on-state update is called each
update and on exit is called on the transitions.
And okay, Excellent.
So now let's continue on.
In here I'm going to create first of all,
the transform for the layer to chase.
Then I'm going to get.
A rigid body 2D.
So boss rigid body, no boss.
Rigid body 2D.
Or you know what? Let's not going to have to
lead this whole game is a 2D game,
so we won't need that and
a vector three dot direction to move.
And so just like regular enemies,
we have the components of the boss walking and so on.
So now that we have these,
it's time for a bit of a challenge.
And your challenge is going to be to
find the IP layer and get the rigid body.
So first of all,
think of where we should be getting all the references.
So usually we use the start,
but now we don't have stopped.
So where should we be?
You think where we should be using a,
where should we be getting all of our components?
Then we'll need to find the player, obviously.
Then we'll need to get the rigid body on the boss.
And I'm going to give you a small hint.
We will need to use the animator from the parameters.
What do I mean by the animator from the parameters?
Let me just show you that.
So if we go in here,
you can see that on the on-state enter,
on state update and on-state exit,
we have certain parameters in here,
and one of them is the animator.
So we have immediate access to the animator.
That's what you're going to use
an order to get the references.
So back and forth to our challenge,
this is a bit hard.
Do your best, try different things,
different tricks, make mistakes, do your best.
There's no pressure on you.
Pause the video right now and go do the challenge.
O K will come back.
So because we don't have start,
we are going to use the on-state enter and away Allstate
enter works is as soon as we enter into the state,
we will set up the parameters and
then we will be seeing what we want to do later on.
For now, we're going to go
ahead and use the player chase.
What is the player Chase is going to be
the game object dot find objects of type.
Or actually where is it find object of type.
And it's going to be the player controller.
Note on top bullet the player controller.
So find the object of type.
I believe we've seen this before.
And we used game object because we can just use
game object without having the mono behavior up here.
So we need the game object class.
Then we get the final object of type.
We get the player controller.
And finally, we need to get
the transport of that game object that we found.
So now we have a reference to the player to chase.
Next, we need the rigid bodies.
So I'm going to say that
the bosses rigid body is equal to the animator component.
And we are going to get the rigid body 2D.
And did we add a rigid body to the boss?
Let's check that out and see if we did.
If we click on the Skelly, not we didn't.
So let's go ahead and add a rigid body 2D.
There we go. So now we have a rigid body.
And let's make sure that we
freeze the rotation on this end.
And we make sure that
the grand scale to 0. There we go. Save that.
If you don't want to be able to push your boss around,
you can make sure to set it to either
kinematic static or maybe even static.
But I think he will not be able to move.
Anyways, let's continue one now we need to make sure that
the enemy or the boss actually starts moving.
So where should we be doing that?
Well, obviously it should be the opposite.
So an update, I'm going to say that we have a vector two,
which is the new position that we should be in.
And it's going to be equal to the vector
to the mist towards.
And what should we be moving towards?
It should be the boss dot,
rigid body dot position.
So this will be, as you can see right here.
First of all, we have the current,
then we have the target,
then we have the distance max.
So here we are going to go ahead
and say that position rigid body.
So of the bosses rigid body obviously.
Then we are going to say that
the player chase dot position is the target.
And I'm going to create up here a public float speed.
And this will be the speed at
which we are going to be moving in.
And then a public float back.
Range, and this will be
an attack range later on the tool use.
So in here what we're going to do is we're going
to say that we are going to move at the speed,
but we are going to add to it Time
dot fixed delta prime and y fixed delta time.
And what's the difference?
You can see in here, the interval in seconds at which
physics and other fixed frames rate updates.
So it's, it's almost the same as delta time,
but it's fixed delta time.
It just adds a bit of extra performance to the game.
And for some reason I noticed when
we use the regular delta time,
we have some weird behavior because we are in a animator.
Maybe that's the reason.
I'm not 100% sure,
but what I've found using fixed delta time,
which is exactly like delta time,
just fixed and more precise.
So let's continue on.
Finally, what do we want to do when
we get into a certain range?
We want to start attacking our player.
So if the vector two dot
distance between the layer
to chase dot position and the rigid body.
The boss rigid body dot position.
If it's less than the attack range
that we've created up here.
While we were creating the speed.
Then in here we are going to say that
the animator that trigger,
the set trigger and we are going to start attacking.
So let's go back into our game.
Let's create a transition
between the walking and the attacking.
And I transitioned between the attacking and the walking.
And in here we're going to make sure that
we don't have any extra time or not
that actually let's skip that because
sometimes might need it.
So in here we are going to say that we want to attack.
This will be the name of the trigger.
The condition to transition from walking and
to the attack is going to be the trigger attack.
I'm going to paste it in here, save that.
And now in here I'm going to
see how are we going to get back.
So first of all, we do,
we go from The Walking,
we start attacking, but then how do we get back?
First of all, let's see how that will look.
So I'm going to run the game
and we are going to look at our player behavior.
So as you can see, he appeared,
but for some reason he is not moving
and his slides away very easily.
So let's go to the syllabus
and let's see what the problem is in here.
Maybe you should make him a bit dynamic or kinematic.
Let's try this again.
And again. He appears he starts walking.
And when we are in range,
as you can see, he is.
There you go.
Everything seems to be working.
The only problem is that we
are being rendered on top of him.
So I'm going to go back.
I'm going to check for these private and the boss layer.
So this is your preference.
Do you want to appear
behind the boss, in front of the boss?
But actually what we want
is maybe to appear behind the boss.
We don't want to be walking over the boss.
So in the layers added,
player, There we go.
So now when we run the game,
now there is an obvious problem in here that okay,
So we are rendered behind the boss. That's good.
He is fighting US,
is doing one attack
than another attack than
walking EBIT than another attack.
But here the problem is that he
is still not walking towards us.
That's because we didn't actually make the boss move.
This was a mistake on my part.
Rigid body on the bus.
We can use the Move position.
And in here we are going to sell it as
the new position. So save that.
You can see right here,
Move position doesn't do,
moves the rigid body to position, save that back.
Now game, run the game.
And now we should see that when the boss appears,
he starts walking towards the layer and he
starts hitting the player and walking towards him.
But as you can see, he is not facing
the right direction and he is
stopping too close to the layer.
That's because if we click on
the syllabus on the walking excuse me,
on the walking right here,
was that you can see that the speed and
the attack range to be maybe a bit bigger.
So let's make it maybe five.
Let's see how that looks. Run the game.
And now he gets close, then you go,
you can see he starts fighting us
and he starts walking towards us.
So that looks kind of good.
I believe we don't want to
be able to walk behind the boss.
I don't like it a lot.
So maybe this should not be a trigger after all.
Maybe you should be able to
just hit the boss on the head.
It's not a huge deal if we can
actually walk through this or
you can make the, for example,
the grid wall changed the wall
to a certain level and make sure that
the boss doesn't interact with wall,
which I think is a really good idea.
Maybe we'll test that out. Let's save that.
But for now, everything seems to be working good.
There is the problem of
obviously the flipping of the enemy.
And we have to do a couple of fixing for the movement,
but we'll keep that for a later video.
For now. I hope you enjoy it.
I hope you are committing your changes
and I'll see you in the next one.