How to make a 2d sprite move a specific distance at a specific speed

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

I’m new to Godot and in this small plat former I’m making i want to create a slide action that would move the sprite a specific distance at a specific speed while making it perform it’s slide animation throughout the duration of the slide but all I’ve gotten so far is a continuous sliding motion that will continue so long as the action is pressed. (P.S I’m trying to make it so the slide happens if the analog stick is flicked on controller/ button is pressed on keyboard and can’t be done in procession i.e You have to finish the “get_up” sequence to be able to slide again.)

Here’s the function i wrote for the sliding


func slide_mechanics():
	if Input.is_action_pressed("slide_left"):
		$Sprite.flip_h = true
		$Sprite.play("Slide")
		velocity.x = -DODGE_SPEED
	elif Input.is_action_pressed("slide_right"):
		$Sprite.flip_h = false
		$Sprite.play("Slide")
		velocity.x = DODGE_SPEED
	$Sprite.play("Get_up")
:bust_in_silhouette: Reply From: exuin

You could set a timer that controls how long the slide is and only move the player according the slide function if the timer is playing.

:bust_in_silhouette: Reply From: magicalogic

You could use lerp() function or Vector2.linear_interpolate().
More about interpolation here.