How to add a double dash

Godot Version

4.3

Question

How to add a double dash where the second dash has a different effect (does extra damage etc), new to coding so not sure what variables would i need to add

this is my code without a double dash:

extends CharacterBody2D

@export var walk_speed = 200.0
@export var run_speed = 600.0
@export_range(0,1) var deceleration = 0.1
@export_range(0,1) var acceleration = 0.1

@export var jump = -400.0

@export var dash_speed = 1000.0
@export var dash_curve : Curve
@export var dash_distance = 300.0
@export var dash_cooldown = 1.0

Get the gravity from the project settings to be synced with RigidBody nodes.

var gravity: int = ProjectSettings.get_setting(“physics/2d/default_gravity”)

var is_dashing = false
var dash_timer = 0
var dash_start_position = 0
var dash_direction = 0

func _physics_process(delta: float) → void:
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta

# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
	velocity.y = jump

var speed
if Input.is_action_just_pressed("run"):
	speed = run_speed
else:
	speed = walk_speed

# Get the input direction and handle the movement/deceleration.
var direction := Input.get_axis("left", "right")
if direction:
	velocity.x = move_toward(velocity.x, speed * direction, speed * acceleration)
else:
	velocity.x = move_toward(velocity.x, 0, walk_speed * deceleration)

#dash 
if Input.is_action_just_pressed("dash") and direction and not is_dashing and dash_timer <= 0:
	is_dashing = true
	dash_start_position = position.x 
	dash_direction = direction
	dash_timer = dash_cooldown

if is_dashing:
	var current_distance = abs(position.x - dash_start_position)
	if current_distance >= dash_distance or is_on_wall():
		is_dashing = false 
	else:
		velocity.x = dash_direction * dash_speed * dash_curve.sample(current_distance / dash_distance)
		velocity.y = 0

if dash_timer > 0:
	dash_timer -= delta 


move_and_slide()

I would handle it using a new var, lets call it Dashes_left

if Dashes_left is 0 then you cannot dash
if Dashes_left is 1 then you will have your second dash effect active
if Dashes_left is 2 then you will have a standard dash

then you could have a function to create a timer to increase your dash amount if Dashes_left < 2.

I don’t know if this is the best course of action, but it is what I would use in my projects.

3 Likes

This works for me, do you know how id go about adding the extra effects for the second dash tho?

you could have an Enum of all of the effects so:

Enum DASH_EFFECTS {effect1, effect2, effect2, etc…}
var:int = dash_type

now you need a function to assign the effect type

func Dash_Effect_Determiner():
…
dash_type = DASH_EFFECTS.effect1
…

and I’m your dash function you need to add a way to carry out the effects. that would look like so:

if Input.is_action_just_pressed(“dash”) and direction and not is_dashing and dash_timer <= 0:
is_dashing = true
dash_start_position = position.x
dash_direction = direction
dash_timer = dash_cooldown
switch dash_type:
DASH_EFFECTS.effect1:
#whatever effect 1 does
DASH_EFFECTS.effect2:
#whatever effect 2 does
etc…

1 Like

Thank you, very insightful