Dash mechanic Help

Godot Version

Godot 4.6.1

Question

Currently working on a dash function for a top-down RPG I’m making and got it to work in 7 of 8 directions… yeah, when moving diagonally up and to the left (W + A on the keyboard) the dash just doesn’t work, I somewhat followed a YouTube tutorial and a little bit of it is improvised.

extends CharacterBody2D

#Movement Constants
const WALK_SPD = 300
const SPRINT_SPD = 500

# Dash Handling
const DASH_SPD = 850
const DASH_DISTANCE = 0.15
const DASH_COOLDOWN : float = 1.0

# dash flags
var can_dash: bool = true
var dash_dir = 0
var dash_timer: float = 0.0
var dash_cooldown: float = 0.0

#debug flags
var dbg_sprint: bool = false

# player movement inputs
func _physics_process(delta: float):
	if dash_timer == 0.0:
		var input: Vector2 = Vector2(Input.get_vector("left", "right", "up", "down"))
		velocity = input * WALK_SPD
		
		# sprint button
		if Input.is_action_pressed("sprint"):
			dbg_sprint = true
			velocity = input * SPRINT_SPD
		else:
			dbg_sprint = false
			velocity = input * WALK_SPD

	_dash_logic(delta)
	move_and_slide()

# THE IMPORTANT PART(Dash Handling) complicated stuff (used a yt tutorial for this)
func _dash_logic(delta: float):
	var input: Vector2 = Vector2(Input.get_vector("left", "right", "up", "down"))
	
	if can_dash and Input.is_action_just_pressed("dash"):
		can_dash = false
		dash_timer = DASH_DISTANCE
		dash_cooldown = DASH_COOLDOWN
		
		dash_dir = input
		velocity = dash_dir * DASH_SPD
		
	if dash_timer > 0.0:
		dash_timer = max(0.0, dash_timer - delta)
	else:
		if dash_cooldown > 0.0:
			dash_cooldown -= delta
		else:
			
			can_dash = true
		

It doesnt work at all or dashes in the wrong direction?

Try printing which keys are pressed. Alternatively print the input. Could be that the keys don’t register properly. That can apparently be a problem when holding several keys at once. Sounds like that could be the case here. Question is why for only this button combination.

After some further testing, I’ve found that neither A+W or A+S work, and to answer your question, it just doesn’t dash at all.

Nothing in the code seems to explain it. Does it work, if you use arrow keys instead of WASD? Modern keyboards shouldn’t have problems with 3 simultaneous key presses though.

I think the reason W and S dashing doesn’t happen is that W (up?) and S (down?) cancel each other out, and the returned vector 2 would be 0,0. I could be wrong! Try checking the returned vectors with a print statement.

Add print(input) right below your var input line.

Yes, I tested it now and up and down cancel eachother out so the vector2 returned is 0,0.

Could you double check the prints for the combination that doesn’t work?

Thank you guys for the help, however I found that binding the dash button to C instead of Q fixed the issue for whatever reason.

Correction, B makes it work, probably just a hardware issue on my end, or the code just doesn’t like it when inputs are too close together.