private IEnumerator Dash()
{
if (!canDash)
yield break;
canDash = false;
isDashing = true;
float originalGravity = playerBody.gravityScale;
playerBody.gravityScale = 0f;
// Store the current velocity
float originalVelocityX = playerBody.velocity.x;
float originalVelocityY = playerBody.velocity.y;
// Apply the dash velocity
playerBody.velocity = new Vector2(transform.position.x * dashSpeed, 0f);
// Wait for the dash time
yield return new WaitForSeconds(dashTime);
// Restore the original horizontal velocity
playerBody.velocity = new Vector2(originalVelocityX, 0f);
// Wait for the dash cooldown
yield return new WaitForSeconds(dashCooldown);
isDashing = false;
canDash = true;
playerBody.gravityScale = originalGravity;
}
This is my code right now, I call it elsewhere. It currently makes me float in place (I can still move normally while floating) and then drops me, nowhere does it apply the movement on the X that is desired, can anyone help? Cheers!