Hello !
I wanted to add a air dash for my platform game but i'm struggling to add it.
I watch a lot of tutorial but i still can't understand why it is not working.

extends CharacterBody2D

#Movement
var speed = 200
var jump_speed = -400
var gravity = 1000
var friction = 0.5
var acceleration = 0.5

#Dash
var dash_force = 400
var can_dash = false
var dash = Input.is_action_just_pressed("dash")

func _physics_process(delta):
	#check if is on floor
	if !is_on_floor():
		friction = 0.1
		acceleration = 0.25
		can_dash = true
	else :
		can_dash = false
		friction = 0.5
		acceleration = 0.5
	
	#Movement
	velocity.y += gravity * delta
	var dir = Input.get_axis("move_left", "move_right")
	if dir != 0:
		velocity.x = lerp(velocity.x, dir * speed, acceleration)
	else:
		velocity.x = lerp(velocity.x, 0.0, friction)
	
	#Dash
	if dash and can_dash == true:
		velocity.x += dash_force
	
	move_and_slide()
	
	#Jump
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = jump_speed

Can you help me please ?

  • kuligs2 replied to this.
  • Screatch dat.
    I realized, you trigger dash but you never watch for if Input.is_action_just_pressed("dash")

    do something like this

    #Dash
    var dash_force = 400
    var can_dash = false
    #var dash = Input.is_action_just_pressed("dash") < --- remove this
    	#Dash
    	#if dash and can_dash == true: <-- remove this line
            if Input.is_action_just_pressed("dash") and can_dash == true
    		velocity.x += dash_force

    how does it not work? what does it do when you dash? demo video?

      kuligs2


      You can see in this video that it's not working, i'm pressing my dash button (shift) everytime i'm in the air.
      The windows size is 640x360 if it can help.

      TheMikega #Dash
      if dash and can_dash == true:
      velocity.x += dash_force

      put a print statement after this to see if when you press button this part of the code gets execute

      velocity.x += dash_force
      print("Dashing: %s " % velocity.x)

      Then maybe make dash_force bigger number? like 4000

      Screatch dat.
      I realized, you trigger dash but you never watch for if Input.is_action_just_pressed("dash")

      do something like this

      #Dash
      var dash_force = 400
      var can_dash = false
      #var dash = Input.is_action_just_pressed("dash") < --- remove this
      	#Dash
      	#if dash and can_dash == true: <-- remove this line
              if Input.is_action_just_pressed("dash") and can_dash == true
      		velocity.x += dash_force

        kuligs2

        Thank you !
        It's working, I watched tutorial that used godot 3 and thought it will not change much between 2 different version.
        Guess I was wrong hehe.