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"):
ADD_SPEED = 300
while ADD_SPEED > 0:
ADD_SPEED -= 3
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