I tried to implement a Megaman-X-like dash in my code a few times but failed miserably. I watched one specific tutorial I found on the youtube but it didn’t work, too. Took a few step backs and tried to breakdown how a Megaman X dash really works.
I got this:
- when you press the dash button without directional influence, you’re sent to the direction you’re looking;
- the dash works like a “better jumping”, as in whenever you hold it, it applies a force to the desired direction. however after a period of time/releasing the dash button, it stops. literally like a normal “mario jump” but with horizontal movement.
- the dash cant be done on the air
- your speed increases whenever you dash (duh)
- you can “spam dash” [though i think if you do it your speed decreases a little?]
- you can quickly change the direction of your dash with directional input, even when you are dashing
though I’ve been struggling a little to get this one down to code.
I’d love to ask two questions, one is how to become better at this “second stage”, that is, turning your “breakdown” into actual code, and if you guys can help me out with some guidance. It would be really appreciated. Just for the sake of it, here’s the previous code where I attempted doing the dash:
void Dash()
{
isDashing = true;
if (isDashing && !Input.GetKey(KeyCode.LeftShift)) // if the player is dashing but not pressing the dash button
{
rb.velocity -= new Vector2 (mov*lowDashMult*Time.deltaTime, 0); //decrease his horizontal speed according to the direction they're pressing, time and "lowDashMult"
}
rb.velocity = new Vector2 (dashSpeed*speed, rb.velocity.y); //actually apply speed
StartCoroutine(StopDash()); //easier way i've found to make unity wait for seconds
}
IEnumerator StopDash()
{
yield return new WaitForSeconds(dashDuration);
isDashing = false;
yield return new WaitForSeconds(dashCooldown);
}
}