Dash nly works when I'm not moving

I’m working for a dash to a 2D platformer, and so my far my works only when I’m not moving, does anyone know why?
Dash code:

if Input.is_action_just_pressed("dash") and canDash == true:
		if isflip == false:
			velocity.x += 2500
		elif isflip == true:
			velocity.x -=  2500
		dashing = true
		canDash = false
		$Timer.start()
		if is_on_floor():
			$Timer2.start()

I’m betting your movement code looks something like this? From the 2D platformer template script:

if direction:
    velocity.x = direction * SPEED
else:
    velocity.x = move_toward(velocity.x, 0, SPEED)

This template has a few weird features to it.

when stopping it frame-dependantly slows to a zero speed, this should be DECELERATION * delta where DECELERATION is about four to eight times SPEED.

when moving it sets the velocity.x to a certain value, rather than accelerating to the desired speed. Any attempt at inserting knockback, dashes, or any horizontal speed impulse requires changing this line to take acceleration. Which behaves similarly to DECELERATION.

Results in something like this:

const ACCELERATION = SPEED * 8
const DECELERATION = SPEED * 6

if direction:
	velocity.x = move_toward(velocity.x, direction * SPEED, ACCELERATION * delta)
else:
	velocity.x = move_toward(velocity.x, 0, DECELERATION * delta)

I Cant put the constants becaus it gives me an error

maybe your SPEED variable is not a const, make both of these a var.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.