Godot Version
Godot 4.6.1
Question
Currently working on a dash function for a top-down RPG I’m making and got it to work in 7 of 8 directions… yeah, when moving diagonally up and to the left (W + A on the keyboard) the dash just doesn’t work, I somewhat followed a YouTube tutorial and a little bit of it is improvised.
extends CharacterBody2D
#Movement Constants
const WALK_SPD = 300
const SPRINT_SPD = 500
# Dash Handling
const DASH_SPD = 850
const DASH_DISTANCE = 0.15
const DASH_COOLDOWN : float = 1.0
# dash flags
var can_dash: bool = true
var dash_dir = 0
var dash_timer: float = 0.0
var dash_cooldown: float = 0.0
#debug flags
var dbg_sprint: bool = false
# player movement inputs
func _physics_process(delta: float):
if dash_timer == 0.0:
var input: Vector2 = Vector2(Input.get_vector("left", "right", "up", "down"))
velocity = input * WALK_SPD
# sprint button
if Input.is_action_pressed("sprint"):
dbg_sprint = true
velocity = input * SPRINT_SPD
else:
dbg_sprint = false
velocity = input * WALK_SPD
_dash_logic(delta)
move_and_slide()
# THE IMPORTANT PART(Dash Handling) complicated stuff (used a yt tutorial for this)
func _dash_logic(delta: float):
var input: Vector2 = Vector2(Input.get_vector("left", "right", "up", "down"))
if can_dash and Input.is_action_just_pressed("dash"):
can_dash = false
dash_timer = DASH_DISTANCE
dash_cooldown = DASH_COOLDOWN
dash_dir = input
velocity = dash_dir * DASH_SPD
if dash_timer > 0.0:
dash_timer = max(0.0, dash_timer - delta)
else:
if dash_cooldown > 0.0:
dash_cooldown -= delta
else:
can_dash = true