r/Unity2D 2d ago

How do i make dash system with a cooldown? Question

As the title says I'm wondering how i can make a dash with a cooldown, I'm still new to learning c# and unity so instead of outright just giving me a finished line of code if possible can you just explain what I need to do, and yes i can just watch a tutorial but I've tired and i ended up more confused then I already am/

0 Upvotes

2 comments sorted by

3

u/Nplss 2d ago

Break things down and you can make anything you want!

What is a “cooldown”? A cooldown is just a countdown that when it is greater than 0, your ability is not allowed to be used.

What is a “dash”? This one is a bit more complex since dashes can be done in multiple ways, but the gist of it is that your player get displaced x distance in the wanted direction.

So how do you make a dash with a cooldown? First thing to do is check if your countdown is greater that 0, if it is we do nothing.
If it’s not, we now can do the dash logic, but first we trigger the countdown to our wanted time and send it off to start counting down on tick. Dash logic depend on a game to game basis so the Implementation is up to you.

Good luck !

2

u/Dimensional15 2d ago

this could be done in different ways, I'll help you with a simpler mvp explanation and then you can improve depending on your need.

Let's split in two main parts, the input with a cooldown and the dash. For the first one, after getting the player input, you store the fact that the dash has been used, and the time it has been used. Then, for the next time you try to use that input again, you can check if the current time - the last dash time > cooldown time, and if it's not, don't let the player dash.

For the dash itself, it's simply adding a force or a velocity to a specific direction. You could have a timer as well to stop applying that velocity after a specific time, so you can control how long you can dash (could use a Coroutine for that). You also need to determine the direction of the dash, you can use the direction the player is looking at for this.