Welcome back, My favorite game developers.
In this video, I'm going to maximize on play.
We've added a dashing mechanic.
So now as we move around,
if I click the Space key, There you go.
You can see that I move a bit faster of a,
but actually doubled times the speed.
So when I dash,
I move two times faster. There we go.
We can see an i can't kill
the enemies to run around them and shoot them.
And yeah, there we go.
So we've added this really
nice-looking and cool mechanic.
So let's not waste any more time and let's get started.
Oh, okay, so now we
can go back and don't player, double-click on him.
Okay, so now what we want to create,
actually the first thing I want to
do is get rid of this image.
Now what we can do is we can turn off the canvas,
but that's not very practical.
But what we can do,
and this is a great opportunity
to teach you something new.
If you click on the canvas,
you can see that the layer and here is, you are.
So if we go in here into the layers,
you can see that we have all the layers right here.
And you can see that we have some kind of lock
and then we can have some kind of I in here.
And if I click on the eye,
you can see that everything under
the UI or everything under the layer UI disappears.
If I click out the player,
they go, you can see the player also disappears.
It's still in the game.
It still works when we start the game.
You can see in the game window, It's still there,
but in the scene, we can't see it.
What's that out of the way?
The next thing we want to do is add
some kind of dashing mechanic,
just like we have in the game Hades.
We can see that we can dash quickly.
We are going to do the same in this game.
It's a bit different, obviously
because of the limitation and sprites.
The limitation in a team.
And we are going to use the sprites in here.
Where are they, these playwrights
sprites for the blue layer.
And you can see that we have this rotating right here.
And this is what we're going to use.
And obviously, obviously actually
in the resources I've left
to another kind of torpedo you can use
that It's a bit different and colors than this one,
but I think that's not a huge problem.
So what are we going to do?
We are going to first of all explain
what the tornado torpedo.
I don't even know what to call it.
Maybe you have a totally different way.
We'll call it the dashing from now on everything will
be the dashing just to avoid any confusion.
So first of all,
the player will move much faster.
So we will increase the movement speed of the player.
And animation will be triggered,
which will make the player go in circles.
And while the player is doing the tornado,
he will be invincible so he can't be hurt by anything.
This is something that we will implement later
on when we add a health system to the player.
For now, just know that this is what will
happen when the player is dashing.
And finally, he can break objects around them.
So as you know the name of this section,
as did the structural objects.
And first of all,
we need to add a way or a bit of
an advanced movement to the player so he can
destroy those game objects
so without any further or blue.
And let's get started.
So the first thing that we want to do is we want
to go to the layer controller,
look how many scripts we have.
I just noticed, that's good.
That means we are increasing our understanding.
Anyways.
First of all, we'll need to create
a way to keep track of the current movement speed.
Because now we have the regular movement speed,
we will have now the dashing movement speed.
So the first thing I want to do is create a private float
and the current movement speed.
And this current movement speed will change
whether we are doing the torpedo or tornado,
and whether we are just simply walking.
Then I'm going to create
a private bool that's going to be called the can dash.
And why are we creating this boolean?
Well, because you'll see
that now an update we want to dash.
So we are going to click some kind of
key and we will start dashing,
but we don't want to be able to dash all the time.
We want to have a cool down for the dash,
and we also want to have some kind of length or the dash.
So we will have this Boolean to keep everything
in check and make sure that we can
dash 20 times in a row.
So the next thing that I'm going to do is I'm going to
scroll down right here and see
where the player is moving.
So I double-click and I
can scroll down and find the Rigo.
We have the player moving and
this is where we add the velocity.
So it's the movement input times the movement speed.
And instead of using the movement speed,
I'm going to say that it is the current movement speed.
And just to make sure that we have
a current movement speed and it's not 0.
And start, I'm going to set
the current movement speed to be equal to the regular.
Movement speed.
There you go.
You can change the name of
the movement speed if you'd like,
you can name the regular movement speed.
I'll just keep it like that.
It's not too confusing for me.
If it is thick for you,
then go ahead and change the name.
Next thing we want to do is we want to set
up the variables 40 dashing.
Let me just add in here a comment that we are dashing.
Dashing and movement by looks.
So I'm going to create
a serialized field and is going to be the float,
and it's going to be the dash speed.
And for now I'm going to set it
to what is our movement speed?
What was the movement speed on the dune player?
Let's see, ten.
Okay, then, so I'm going to make this at least 20,
maybe even more later on.
By the way, we will be able to control from the spectral.
So this is not a problem.
And the next thing I want to make sure we have
is these two variable which is the or no,
actually this should be private.
Or let's go ahead and make them serialized.
So the dash length,
which is going to be set as 0.5 f.
So this is how long we are dashing.
And then we will have the dash cool down,
which is going to be the time
between each dash and sell it at one.
So now we have the option to play around with the dashes,
the dash speed, dash length, and the dashed.
Cool. Now 1 second.
Okay, great.
Now an update.
We are going to go ahead and create
a method in here are not method actually.
First of all, before we create the method,
we are going to check for some kind of input.
And based on that input,
we are going to go ahead and change the current speed,
make it the dash speed,
and then make sure that we can no longer dash.
You can use whatever button you want.
Maybe I'll use the space.
I'm going to use input that get key down.
And you can see that this returns
a true during the frame,
the user starts pressing a key
and identified by a key code.
So hit tab, open up the brackets.
I'm going to write in here
key code dot space, and there you go,
We can see that we have the options to map on
our keys and we want to make sure that we can dash,
open this up in here.
So the first thing we do is
the current movement speed becomes the dash speed.
And can dash is set to false. So there we go.
We click on the space.
We check if we can dash.
If both are true,
the current movement becomes the dash speed,
so it's a lot faster.
So the current movement in here becomes 20,
not ten, we move faster and we cannot no longer dash.
Of course, we will have to reset
these values in just a bit.
But for now, let's test this out and see if it works.
Oh, and we forgot to do something
which is create the actual animation.
And let's do that in just a bit for now,
let's test out our mechanics of they work.
So I am going to make this a bit bigger.
So I move around.
If I had the space key.
Yep, no, nothing happened.
And why is that?
Because we have some kind of error.
Okay, This is very
annoying but doesn't impede us from anything.
What seems to be the problem?
I pressed Space, get keydown, declare controller.
Okay, welcome back.
So after a bit of digging and I was
very confused why this was not working.
And that's because the candidate was not set.
So it wasn't true.
I made sure to set it to true and start.
And now I've also had this debug dot log.
So let me just show you what I was doing.
I was confused.
If need be.
Problem was the current movement
wasn't changing for some reason.
So I had the debug dot log set right here,
and I was looking in the console.
So on notice that it kept its state,
and so I realized this method was not being caught.
So I knew that pressing space was okay.
They can bash probably wasn't.
I set it to true. It worked out.
Let me remove this, save that.
This is just the power of debug.
And as you can see, sometimes
not everything works out perfectly.
Sometimes you need to dig into things.
So now when I move around,
you can see the movement.
You can realize how fast it
is when I press the space key.
There we go.
You can see that I'm moving a lot faster,
okay, with that done,
the next step is to actually take us
back to the regular speed and also make sure
that the dash cool-down works and weekends
then again after the wherever the dash cool down.
And that's going to be actually part of your challenge.
Your challenge is to create two cotyledons.
So the first will be the cool-down counter where we
will wait and then be able to torpedo again.
And the second one will be the speed at
which we move so that the end of this,
we'll put the speed back to its normal speed.
So those instructions pause the video right
now and go do the challenge.
Okay, welcome back.
So what are we going to do in here?
As soon as we dash we have the movement,
we are going to have to call routines.
The first one in here is going to be an eye enumerator.
And it's going to be the dash.
Cool down. And in here we are going to yield, return new.
Wait four seconds.
And we are going to wait for the dash, pull down.
And when it finishes,
we are going to say that can dash equals true.
And then we are going to create another I numerator,
which is going to be called the dash length.
And you know what? I think that the name isn't enough.
I'm going to call it the dash length counter,
just so we know what's going down and
the dash cool down counters.
Sure.
Let's call it the dashboard down counter.
And I'm going to copy this.
So yield, return new weight for second,
but now it's the dash length.
And when we're done with the dash,
This means that we've dashed for,
I don't know, however long the dash cool-down will be.
However long you want the player to move fast.
I will keep it at 0.5.
Maybe we'll change it. You can do whatever we want.
I'm going to set the current movement speed to be equal
back to the regular movement speed.
So finally, we need to start the coltan,
which is the dash,
cool down counter, and then start another co-routine.
And it's going to be the dash length counter.
Dash length counter.
Okay. So I was looking and
wondering why this was still red.
That's because we didn't
actually called the dash cool down counter.
We just call the variable up there.
We save that.
So now we press the space.
We said the current movement to dash speed.
Without it, we cannot dash any longer.
We start the co-routine.
The dash cool down.
After the cool down finishes,
we can then dash again and the dash length.
So save that.
We go back into our game.
We run the game.
And there we go.
We can see that now we move fast.
And then we start moving slogan,
so fast, then slow again,
and fast, then slow again.
How cool is that?
There we go, everything is working.
And if I try to dash multiple times,
you can see that I cannot do that.
I have a period of time in-between.
I cannot move very fast as much as I would like to.
So I hope you enjoy it.
I hope you are committing
the changes created a torpedo movement,
I'm going to call this because it sounds really cool.
Stage all created.
Torpedo, movement.
Commit the changes.
And I'll see you in the next video where we will actually
be adding visualization to this torpedo, to this dashing.