Godot Version
4.2.1
Question
I have watch some tutorials on Youtube to make a jump buffering and coyote jumping, but it dont work/my double jump stop working
Here’s my code :
extends CharacterBody2D
@export var speed = 150
@export var gravity = 20
@export var jump_force = 300
@export var down_speed = 700
@export var dash_speed = 450
@export var superjump_speed = 500
var dashing = false
var can_dash = true
#max jump, dash, superjump
var jump_count = 0
var max_jumps = 2
var dash_count = 0
var max_dash = 1
var max_superjump = 1
var superjump_count = 0
func _physics_process(delta):
if !is_on_floor():
velocity.y += gravity
if velocity.y > 500:
velocity.y = 500
#pour faire des petits saut
if Input.is_action_just_released("jump") and velocity.y < 0:
velocity.y = jump_force / 5
if is_on_floor():
jump_count = 0
dash_count = 0
superjump_count = 0
if Input.is_action_just_pressed("jump"):
if jump_count < max_jumps:
jump_count += 1
velocity.y = -jump_force
if Input.is_action_pressed("move_down"):
velocity.y = down_speed
var horizontal_direction = Input.get_axis("move_left","move_right")
velocity.x = speed * horizontal_direction
#if horizontal_direction != 0:
#$AnimationPlayer.flip_h = (horizontal_direction == -1)
#floor
if is_on_floor() and horizontal_direction == 1:
$AnimationPlayer.play("walk")
if is_on_floor() and horizontal_direction == -1:
$AnimationPlayer.play("walk")
if is_on_floor() and horizontal_direction == 0:
$AnimationPlayer.play("idle")
#jump
if !is_on_floor() and velocity.y < 0:
$AnimationPlayer.play("jump")
#fall
if !is_on_floor() and velocity.y > 0 and horizontal_direction == 1:
$AnimationPlayer.play("fall")
if !is_on_floor() and velocity.y > 0 and horizontal_direction == -1:
$AnimationPlayer.play("fall")
if !is_on_floor() and velocity.y > 0 and horizontal_direction == 0:
$AnimationPlayer.play("fall")
else:
if horizontal_direction != 0:
$AnimationPlayer.flip_h = (horizontal_direction == -1)
if horizontal_direction:
if dashing:
velocity.x = dash_speed * horizontal_direction
if Input.is_action_just_pressed("dash") and can_dash:
if dash_count < max_dash:
dash_count += 1
dashing = true
can_dash = false
$dash_timer.start()
$dash_again_timer.start()
if Input.is_action_just_pressed("super_jump"):
if superjump_count < max_superjump:
superjump_count += 1
velocity.y = -superjump_speed
move_and_slide()
#stop dashing
func _on_dash_timer_timeout():
dashing = false
func _on_dash_again_timer_timeout():
can_dash = true
print(velocity)