extends KinematicBody2D
const DASH_SPEED = 2000
const MAX_SPEED = 128
const ACCEL = 512
const FRICTION = 0.30
const GRAVITY = 600
const JUMP_FORCE = 200
const AIR_RESISTANCE = 0.02
var vel = Vector2.ZERO
onready var sprite = $Sprite
onready var animationPlayer = $AnimationPlayer
func run(directionstrength, delta):
animationPlayer.play("Run")
vel.x += directionstrength * ACCEL * delta
vel.x = clamp(vel.x, -MAX_SPEED, MAX_SPEED)
sprite.flip_h = directionstrength < 0
func jump():
vel.y = -JUMP_FORCE
func applyfriction():
vel.x = lerp(vel.x, 0 , FRICTION)
func jumpRelease():
vel.y = -JUMP_FORCE/2
func dash(directionstrength):
if directionstrength > 0:
vel.x += DASH_SPEED
elif directionstrength < 0:
vel.x += -DASH_SPEED
else:
vel.x = 0
func _physics_process(delta):
vel.y += GRAVITY * delta
var x_direction = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
if x_direction != 0:
run(x_direction, delta)
else:
animationPlayer.play("Idle")
if is_on_floor():
if x_direction == 0:
applyfriction()
if Input.is_action_just_pressed("jump"):
jump()
else:
animationPlayer.play("Jump")
if Input.is_action_just_released("jump") and vel.y < -JUMP_FORCE/2:
jumpRelease()
if x_direction == 0:
vel.x = lerp(vel.x, 0 , AIR_RESISTANCE)
if Input.is_action_just_pressed("dash"):
dash(x_direction)
vel = move_and_slide(vel, Vector2.UP)
How do I make it so that my dash only works one time and resets when you jump again. I cant wrap my head around it. Thanks for the help and sorry for the bad code.