What can I do to fix this problem in the dash of my 2d platformer?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BigManUnicorn

I’ve coded a dash for my 2d platformer, and as far as I can see, the code is right. The dash is kind of working too, but it doesn’t work if I’ve pressed any other key. So, if I press any other key, it doesn’t work, which is not desirable.

I’d be most grateful if any of you guys would be so kind to help me out. I want to know what the problem is with the dash. Thanks in advance!!

The code is as follows:

extends CharacterBody2D

const SPEED = 300.0
const JUMP_VELOCITY = -400.0

Get the gravity from the project settings to be synced with RigidBody nodes.

var gravity = 500

var is_jump_cancelled = Input.is_action_just_released(“ui_accept”) and velocity.y < 0.0
var is_falling = velocity.y > 0.0
var double_jump = Input.is_action_just_pressed(“ui_accept”) and is_falling
var max_jump = 2

var canDash = true
var dashing = false
var dashDirection = Vector2.ZERO

func dash():
if is_on_floor():
canDash = true

if Input.is_action_just_pressed("Dash") and canDash:
	velocity = dashDirection.normalized() * 3000
	canDash = false
	dashing = true
	await get_tree().create_timer(1).timeout
	dashing = false

func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta

if is_on_floor():
	max_jump = 0
if Input.is_action_pressed("Right"):
	dashDirection = Vector2(1,0)
if Input.is_action_pressed("Left"):
	dashDirection = Vector2(-1,0)
# Handle Jump.
if Input.is_action_just_pressed("Jump") and is_on_floor():
	velocity.y = JUMP_VELOCITY
	max_jump += 1
const double_jump_velocity = -600
if not is_on_floor() and max_jump < 2:
	if Input.is_action_just_pressed("Jump"):
		velocity.y += double_jump_velocity
		max_jump += 1
if is_jump_cancelled:
	velocity.y = 0.0

# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction = Input.get_axis("Left", "Right")
if direction:
	velocity.x = direction * SPEED
	velocity.x = move_toward(velocity.x, 0, SPEED)