Godot Version
4.1.3
Question
I’m new to GDScript and Godot as a whole. I made a script for my player to be able to move and dash. It works after I’ve messed with it enough. However, it is very messy. Does anyone have suggestions for making this a little cleaner/easier to read?
Thanks
extends CharacterBody2D
@export var speed = 400
@export var dash_speed = 5000
@export var can_dash = true
var is_dashing = false
var dash_duration = 10
@export var dash_duration_time = 10
@export var dash_cooldown = 200
func get_input():
if !is_dashing:
var input_direction = Input.get_vector("left", "right", "up", "down")
if input_direction and Input.is_action_pressed("dash") and can_dash:
velocity = input_direction * dash_speed
is_dashing = true
else:
velocity = input_direction * speed
func _physics_process(delta: float) -> void:
get_input()
move_and_slide()
func _process(delta: float) -> void:
dash_timer()
print(is_dashing)
func dash_timer() -> void:
if is_dashing:
dash_duration -=1
if dash_duration <=0:
is_dashing = false
can_dash = false
dash_duration = dash_duration_time
if !can_dash:
dash_cooldown -=1
if dash_cooldown <=0:
can_dash = true
dash_cooldown = 200