- Home /
Help Creating Double Tap Dash for 3D Game
I'm working on a first person game and want to add an mechanic that allows for a directional dash when double tapping any of the movement keys. The main requirements I want for the script are to allow for dashes to be chained together on the ground (with a very short delay in between each one), and for it to limit to 1 dash when airborne. However I'm stuck trying to figure out where to begin with implementing double tap inputs.
I have already made adjustments to the FirstPersonController script included in the Unity Standard Assets and don't know how easy it would be to add the dash mechanic to that or just make it into an additional script. Any suggestions or guidance would be appreciated, I'm not very experienced when it comes to coding.
Answer by SSEthanCray · Jan 08, 2018 at 02:39 AM
This may or may not be the best way of doing this, but you could make an int variable. Make it increase every time you click one of the movement keys. Also, when you press a movement key start a coroutine which sets the variable back to 0 after like 0.5 seconds. Then, make it so if your int ever equals 2, then make your dash. Which could just be an addforce. Heres an example:
private int dashCheck;
void FixedUpdate () {
if (Input.GetKeyDown(KeyCode.W) {
//Your movement code
dashCheck++;
StartCoroutine(dashWaiter());
}
if (dashCheck >= 2) {
//adforce blah blah blah
}
}
IENumerator dashWaiter () {
yield return new WaitForSeconds(0.5f);
dashCheck = 0;
}
Your answer
Follow this Question
Related Questions
My character cant jump 2 Answers
Slowing ground effect 2 Answers
Get other GameObject's script name 2 Answers
help with not working AI system 2 Answers