- Home /
Need some help with my dash move
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.
Answer by Robotic_Soul · Aug 29, 2018 at 07:20 AM
Play around with the velocity (make it smaller). That looks like the probable source of your confusion.
Thanks for the response but lowering the velocity will just teleport my character a shorter distance.
This is when dashSpeed is on 50, changing it to a lower value like 10 just shortens the distance.
Your answer
Follow this Question
Related Questions
Smooth movement using Rigidbody2d 3 Answers
Adding a slide/velocity effect to a non-rigidbody2D object 0 Answers
Object jitters when the scene starts 0 Answers
Character won't move (Fixed) 1 Answer
Stopping an object immediately 1 Answer