Welcome back my favor the game developers.
In this video, we are going to be fixing a couple
of bugs or inconveniences and our bosses movement.
So now when we run the game and there
are a couple of small tweaks that you might not notice.
So for example, now,
if we go away, we don't have the double attack.
And we also can see that our enemy
is being flipped every single time.
So with that out of the way,
let's not waste any more time and let's get to flipping.
Oh, okay, So now that we have established
the first type of walking and a pyruvate attacking.
Next thing we're going to do is we're going to be
fixing the boss movement and we're going
to be moving forward with it throughout
the entire boss state machine, SAP.
So let's get started.
The first thing I want to fix this, the double attack.
What's the double attack?
Well, if I run the game,
I'm going to keep it as it is right here.
As you can see, he comes close,
he attacks once, twice.
If I get away,
he's still attacks one.
So 12, this is the double attack.
We don't want that to happen.
So in order to avoid it,
I'm going to open up the Visual Studio and
here and on the on-state exit.
So when we exit from the boss walk,
I'm going to go ahead and access the animator.
And I'm going to reset the trigger.
So in here I'm going to say again attack.
So what this will do is,
you can see right here when we are in a certain distance,
we trigger the attack.
So we go into the attack.
But then as soon as we exit from the walking,
we are going to reset the trigger
so we are no longer in the attack.
So back in here,
we no longer attack twice.
So now if I run the game,
the boss enemies should only attack once we had tax.
So tax, we go away. There we go.
You can see that he only attacks once.
Great, Well that fixed.
The next thing I would like to fix
is the attacking animation.
So you'll notice that he doesn't do
the full two swings up and down.
You're not the only one up and then
he stops. Why is that?
Well, because it's the exit time
right here on the transition.
So if I click on these, Kelly,
and you'll notice here on
the preview when I make the game run,
he shoots once and then he goes back to walking,
which is not something that we want.
So instead what I'm going to do is I'm going to set
the exit time to play about 90 percent of the move.
Yep.
There we go. Maybe even more, just a little bit more.
So maybe 97 ish of the move.
Let's see how that looks.
And all of this needs to be calibrated
based on how you want your game to feel.
So there we go.
We attack once, twice down and down.
There we, then again, we start walking.
Excellent.
One more thing that is a little bit bothering in here is
the exit time on the walking to the attack.
So now we have everything set up.
So now we should see
a bit of a smoother way. There we go.
So we attack, we walk, we attack, we walk,
we attack, we walk a bit and we keep
pushing towards the player.
But obviously there is one thing still missing and
that is that the enemy isn't looking in our direction,
which is something I would call
a huge problem because of the way
our melee attack will be set up.
So let's fix that.
The first thing we're gonna do is obviously we are
going to rotate the player just like we wrote it.
Enemies.
But where do we do this?
We might want to do this and the walking.
Well, what if we are attacking?
We also want to be looking at the player
and shouldn't we be also
looking at the player and shooting?
So this seems to be something that is
more general and not state based.
So we are going to create a script in here that
is called the boss controller.
And I'm going to wait for it to compile and add
this boss controller to
these Kelly boss game object in here.
And in here, I'm going to first of all
get a reference to the player to chase.
So a private void.
Void, void I had transformed.
And the layer to chase.
There we go, save that now and start.
I'm going to go ahead and say that the player to chase
is equal to the final object of type.
The player controller.
And I'm going to go ahead
and access the transform on that.
So now we have the player to chase ready to go.
Now the next thing to do is to actually start flipping.
The boss whenever the player goes
from one side to the next of the enemy.
So because we've done this already,
I'm going to issue you it as a challenge.
And your challenge is to rotate
the boss in the right direction.
So first of all, check for the position
of the boss relative to the player's position.
Remember, we'd get that through
the transforms based on that,
rotate the bus transport around the y-axis.
So you'll need to flip 180 degrees.
So it's similar to the way we were flipping the weapons,
not just the NMI.
You'll need to add the other way
around, of course, obviously.
And then call that method before walking the enemy.
Test it out.
Is there a problem?
Why is there a problem?
So you will obviously
encounter a problem. No worries about that.
Do your best.
Find the flipping way,
and I'll see you in just a bit.
Okay, welcome back.
So in the update,
I'm going to check if the transform,
the position dot x,
which is that the boss,
is greater than the layer to chase that position, the RX.
And by the way, this is based on
how the mass is initially looking.
So if he was looking the other way around,
We might have wanted to check this the other way around.
So anyways, if the position of
the boss is greater than
the position of the player to chase,
obviously on the x-axis, only.
Then what we're going to do is in here we are going
to get the transform dot position.
And we are going to,
excuse me, the Transform Rotate.
Whereas it rotate.
And then 0 F on the x-axis and
180 on the y-axis and 0 on the z-axis.
And why is that? If we go back into our game,
and if we get these Kelly boss,
if we do a rotation right here, there we go,
you can see that he rotates the other way around,
which is exactly what we want.
So we are going to also make sure that
else if we transform that position,
but this time it's the other way around.
That means that the player is what happened.
The player is the on the other way.
Then we are going to make sure to
flip the enemy back again.
So there we go.
Save that.
So now if we go back in here,
and what's the problem?
So maybe we did a typo in here. Yep, there we go.
So back in, again,
we run the game.
Let's see what happens.
And there we go.
So obviously there is a small problem.
What the, what was the problem?
Obviously, our boss enemy
is having some kind of a seizure.
And why is that happening?
Well, because we are trying to flip.
So notice what happens in here on the rotation,
we are flipping and then we are flipping back.
We are trying to flip the enemy,
I mean the boss based on the players direction.
But because we are calling it every single frame and
because of the animation that makes
us walk in a certain direction,
we are having this constant flipping all the time.
So what we're going to do is back in here,
we are going to create a variable that will
check if we have flipped or not.
So in here, I'm going to create a public.
And just to keep it public for now,
obviously we will not keep up like forever.
So if is flipped
lipid and I'm going to set it to false at the beginning.
So in here we're going to check if we have a flippant.
That means is flipped is equal
to false because this is
the regular direction that we're looking at.
If the player is on the left side, right here.
So if the player is on the left side,
we don't want to be flipped.
And in here is flipped is equal to true.
Sorry.
For some reason, the tab isn't taken what I want.
Visual Studio Community isn't keeping up with me.
And then we are going to add
it in here into our conditions.
So if the player is on the left side and,
and is flipped, so he is flipped,
then we are going to flip him back to the other side.
And in here, if he is not flipped,
then we are going to flip him back.
So I hope you understand what's happening in here.
First of all, we have the is
flipped at the beginning, it's false.
So in here, this will not work only when the player is on
the other side of the path
and we have not flipped, then we'll flip.
We'll set this to true,
and this will allow us to not flip back again when we
are obviously not needing to be flipped.
So run the game.
And you'll notice now that the enemy appears,
he goes after us.
Obviously the distance needs to be adjusted a bit.
And then when we go to the other side,
whereas these flipped, there we go.
You can see that there we go.
He is flipped.
Okay.
He is not flipped.
He is flipped.
He is not flipped.
So there we go.
Now we have butter,
movement and butter and
a mission transitions may
be a better distance management would be good.
So five I think is a lot,
maybe 3.5 is a good number.
I don't want the player or
actually the enemy to be hitting V player.
Maybe even three is good.
I'll save that.
We added a bit of transition.
Take your time and play around with
the transitions and make them perfect two-way,
you would like to,
with that out of the way, make
sure to commit your changes.
I hope you enjoy it and I'll see you in
the next video where we will be setting up
the actual mainly attack and start
hurting our player and not just swinging MC.
So see you there.