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