How to implement a dash

Quite simple example to work on top of it:

extends CharacterBody2D

const SPEED := 100.0
const DASH := 300.0

var tween: Tween
var dash_velocity := 0.0

func _physics_process(delta):

	if Input.is_action_just_pressed("attack"):
		dash_velocity = DASH
		if tween:
			tween.stop()
		tween = create_tween()
		tween.tween_property(self, "dash_velocity", 0, 0.3).set_ease(Tween.EASE_OUT)
	
	var direction = Input.get_axis("move_left", "move_right")
	
	if direction:
		velocity.x = direction * (SPEED + dash_velocity)
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)

	move_and_slide()

Hope it helps as starting point.

This is the feature you can rely on for that kind of transitions: Tween — Godot Engine (stable) documentation in English

2 Likes