How to make my AnimatedSprite dash/move towards a position with pressing Shift? ( Im thinking of it as an ability)

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

So i have an AnimatedSprite and i want it to dash to where it is currently looking on the x axis, and i want it to only dash with a certain speed/certain amount of time and then stop immediately. Is that possible?

:bust_in_silhouette: Reply From: DigitalDrako

While this surely isn’t the best way to do this, a simple solution would be to change your velocity before your move and slide function like this:

if Input.is_action_just_pressed("dash"):
  var mouse_direction = get_local_mouse_position().normalized()
  velocity = Vector2(DASH_SPEED * mouse_direction.x, DASH_SPEED * mouse_direction.y)

you can fiddle around with dash speed so the player dashes within your designated time range and speed.