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 ?