Godot Version
Godot 4.4.1
Question
`as you probably already understood, I am a newbie in godot, I have a problem with creating a dash, I more or less understand how to do it, but either I am very stupid, or there is a typo, or godot is just making fun of me.
I will leave the code to your discretion, even if no one helps me here, I don’t even know what to do next.`
extends CharacterBody2D
@export var WALK_SPEED: float = 335.0
@export var JUMP_VELOCITY: float = -500.0
@export var ACCEL: float = 1000.0
@export var DECCEL: float = 700.0
@export var DASH_SPEED: float = 4
var is_dashing: bool = false
@onready var dashcd = $dash_cd
@onready var soundcontrol = $jump_sound
@onready var soundcontrol2 = $walk_sound
@onready var soundcontrol3 = $dash_sound
@onready var animcontrol = $anim
func _ready() -> void:
dashcd.timeout.connect(stop_dash)
func _physics_process(_delta: float) -> void:
if not is_on_floor():
velocity += get_gravity() * _delta
if Input.is_action_just_pressed("mov_jump") and is_on_floor():
soundcontrol.play()
velocity.y = JUMP_VELOCITY
if Input.is_action_just_released("mov_jump") and velocity.y < 0:
velocity.y = JUMP_VELOCITY / 4
var mov := Input.get_axis("mov_left", "mov_right")
if mov:
if is_dashing:
velocity.x = mov * WALK_SPEED * DASH_SPEED
else:
velocity.x = move_toward(velocity.x, WALK_SPEED * mov, ACCEL * _delta)
else:
velocity.x = move_toward(velocity.x, 0, DECCEL * _delta)
if Input.is_action_just_pressed("mov_dash"):
if !is_dashing and mov:
start_dash()
if velocity.length():
if !soundcontrol2.playing:
soundcontrol2.pitch_scale = randf_range(.8, 1.2)
soundcontrol2.play()
else:
soundcontrol2.stop()
func _process(_delta: float) -> void:
if Input.is_action_pressed("mov_right"):
animcontrol.flip_h = false
animcontrol.play("mov")
elif Input.is_action_pressed("mov_left"):
animcontrol.flip_h = true
animcontrol.play("mov")
elif Input.is_action_just_pressed("mov_dash"):
animcontrol.play("dash")
else:
animcontrol.play("idle1")
move_and_slide()
func start_dash():
is_dashing = true
#if not dashcd.connect("timeout", self.stop_dash):
#dashcd.connect("timeout", self.stop_dash)
dashcd.start()
func stop_dash():
is_dashing = false