- Edited
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)