# Godot 3 - Trying to make a character dash (wavedash)

So, I'm trying to make a character do a wavedash in Godot 3 and I don't know what I'm missing here. When I press 'Z', the character should burst speed and then a few miliseconds later it should decelerate back to the normal speed. Tried to use a while loop, adding the var to the motion, but it didn't work.

Here's the code (testing only in the right direction).

extends KinematicBody2D
const UP = Vector2(0, -1)
const GRAVITY = 20
const ACCELERATION = 50
var MAX_SPEED = 150
var JUMP_HEIGHT = -400
var MAX_DSPEED = 300
var motion = Vector2()
var CAN_DASH = true
var ADD_SPEED = 0

func _physics_process(delta):

motion.y += GRAVITY
var friction = false

if Input.is_action_pressed("ui_right"):
motion.x = min(motion.x+ACCELERATION, MAX_SPEED)
$Sprite.flip_h = false$Sprite.play("Run")
if Input.is_action_pressed("dash"):
while ADD_SPEED > 0:
motion.x = min(motion.x+ADD_SPEED, MAX_DSPEED)

elif Input.is_action_pressed("ui_left"):
motion.x = max(motion.x-ACCELERATION, -MAX_SPEED)
$Sprite.flip_h = true$Sprite.play("Run")
else:
$Sprite.play("Idle") friction = true motion.x = lerp(motion.x, 0, 0.2) JUMP_HEIGHT = -400 if is_on_floor(): if Input.is_action_just_pressed("ui_up"): motion.y = JUMP_HEIGHT if friction == true: motion.x = lerp(motion.x, 0, 0.2) else: if motion.y < 0:$Sprite.play("Jump")
else:
\$Sprite.play("Fall")
if friction == true:
motion.x = lerp(motion.x, 0, 0.05)
motion = move_and_slide(motion, UP)
pass


You can't use a while loop in this case. When you execute your script and press the dash button you while loop is processed before the next rendering or physics step. That means you just change you motion.x value 100 times until the add_speed variable has a value of 0.
Since you use the add_speed only for the dash, I think the easiest way to perform the dash with your code is to reduce the add_speed in each call of the physics_process function. For example by adding the following line before(!) the if Input.is_action_pressed("ui_right"): part:
if add_speed > 0: