Hello I'm a new game dev trying to make a platformer with the typical dash mechanic my code has no errors but when playing, the dash just entirely does not work.
my code is below I'm sorry if I'm just missing something simple.
extends KinematicBody2D
const UP = Vector2(0, -1)
const GRAVITY = 22
const MAXFALLSPEED = 350
const MAXSPEED = 150
const JUMPFORCE = 420
const ACCEL = 100
#dashing var
var dashDirection = Vector2.ZERO
var canDash = false
var dashing = false
var velocity = Vector2()
var screen_size
var motion = Vector2()
var facing_right = true
var start_position = Vector2.ZERO
var facing
func _ready():
start_position = position
screen_size = get_viewport_rect().size
func _process(_delta):
if position.y > 250:
position = start_position
$fps.text = str(Engine.get_frames_per_second())
func _physics_process(delta):
dash()
motion.y += GRAVITY
if motion.y > MAXFALLSPEED:
motion.y = MAXFALLSPEED
if facing_right == true:
$Sprite.scale.x = 1
else:
$Sprite.scale.x = -1
motion.x = clamp(motion.x, -MAXSPEED, MAXSPEED)
if Input.is_action_pressed("right"):
motion.x += ACCEL
facing_right = true
$AnimationPlayer.play("Running")
elif Input.is_action_pressed("left"):
motion.x -= ACCEL
facing_right = false
$AnimationPlayer.play("Running")
else:
motion.x = lerp(motion.x,0,0.2)
$AnimationPlayer.play("Idle")
if is_on_floor():
if Input.is_action_just_pressed("jump"):
motion.y = -JUMPFORCE
if !is_on_floor():
if motion.y < 0:
$AnimationPlayer.play("Jump")
elif motion.y > 0:
$AnimationPlayer.play("fall")
motion = move_and_slide(motion, UP)
func respawn():
position = start_position
func dash():
if is_on_floor():
canDash = true
if Input.is_action_pressed("right"):
dashDirection = Vector2(1,0)
if Input.is_action_pressed("left"):
dashDirection = Vector2(-1,0)
if Input.is_action_just_pressed("dash") and canDash:
velocity = dashDirection.normalized() * 100000
canDash = false
dashing = true
yield(get_tree().create_timer(1), "timeout")
dashing = false
canDash = true