I’m fairly new to Unity and I’m trying to implement a dash mechanic for my 2D side-scroller.
Script 1:
public void FixedUpdate()
{
bool dash = Input.GetButtonDown("Dash");
m_Character.Dash(dash);
}
Script 2:
public void Dash(bool dash)
{
if(!m_Grounded) //Check if player on ground
dash = false;
if(dash)
{
float dashSpeed = 50f;
float dashTime = 0.5f;
m_Anim.Play("PlayerDash");
while(dashTime > 0)
{
if(m_FacingRight)
{
m_Rigidbody2D.velocity = Vector2.right * dashSpeed;
}
else
{
m_Rigidbody2D.velocity = Vector2.left * dashSpeed;
}
dashTime -= Time.deltaTime;
}
}
}
What happens is my character teleports based on m_Rigidbody2D.velocity once. I want it to be similar to most side-scrollers like Megaman, Hollow Knight, etc.