Hi, i'm trying to add a dash function to my top down shooter game. I have movement with WASD and when i click the player is dashing towards that position but with my current setup the dash is super short and i can't figure out why the length can't be changed.

(idk why the code won't format correctly)

var speed = 200
var can_move = true
var direction
var mousedirection
var dash_speed = 10000

func _physics_process(delta):
	
	if (get_local_mouse_position().x > 0):
		$AnimatedSprite.set_flip_h(false)
	else:
		$AnimatedSprite.set_flip_h(true)
	
	direction = Vector2()
	var velodash = Vector2()
	
	if Input.is_action_just_pressed("dash"):
		var mouse_direction = get_local_mouse_position().normalized()
		velodash = Vector2(dash_speed * mouse_direction.x, dash_speed * mouse_direction.y)
		velodash = velodash.normalized()
		direction = move_and_slide(velodash)

	if can_move == true:
		if Input.is_action_pressed("ui_up"):
			direction.y -= 1
		if Input.is_action_pressed("ui_down"):
			direction.y += 1
		if Input.is_action_pressed("ui_left"):
			direction.x -= 1
		if Input.is_action_pressed("ui_right"):
			direction.x += 1
	
	direction = direction.normalized() * speed
	direction = move_and_slide(direction)

Maybe it's from using action_just_pressed. Does it go after it when you click the mouse or what?

Looking at the code, I think @fire7side is correct, that it’s probably because you are using is_action_just_pressed. If you want the character to dash to the mouse while the mouse is held, try using is_action_pressed, which should return true as long as the mouse is held.

If it is just the distance, the issue is likely because you are normalizing the dash direction, which makes the Vector2 have a length of 1. Instead, what you want to do is something like this:

# the mouse direction is normalized, so it will be in the 0-1 length
var mouse_direction = get_local_mouse_position().normalized()
# multiply by dash_speed to go dash_speed units in that direction!
# if you normalize after this, it’s length will be 1 instead of dash_speed
velodash = mouse_direction * dash_speed
direction = move_and_slide(velodash)
a year later