diff --git a/Characters/player.gd b/Characters/player.gd index 72f0248..2cd775d 100755 --- a/Characters/player.gd +++ b/Characters/player.gd @@ -3,6 +3,12 @@ extends CharacterBody2D const MOVE_SPEED = 200.0 const CLIMB_SPEED = -150.0 const JUMP_VELOCITY = -250.0 + +# Time window (in seconds) on when to auto-jump when pressing jump key +# before landing on the ground. +const TOTAL_JUMP_BUFFER_S = 0.1 +var jumpBufferTimeLeft = 0.0 + const WALL_SLIDE_MODIFIER = 0.1 const ROTATE_TO_WALL_SPEED = 25 # How quickly to rotate the sprite when clinging to a wall. @@ -34,9 +40,17 @@ func _physics_process(delta: float) -> void: elif not is_on_floor(): velocity.y += get_gravity().y * delta - # Handle jump. - if Input.is_action_just_pressed("jump") and is_on_floor(): + # Jumping! And also jump buffering. + if Input.is_action_just_pressed("jump") and not (is_on_floor() or is_on_wall()): + jumpBufferTimeLeft = TOTAL_JUMP_BUFFER_S + print("start jump buffer") + + if ((Input.is_action_just_pressed("jump") or jumpBufferTimeLeft > 0.0) + and is_on_floor()): velocity.y = JUMP_VELOCITY + jumpBufferTimeLeft = 0.0 + if jumpBufferTimeLeft > 0.0: + jumpBufferTimeLeft -= delta # Quick setup for oozing up walls if verticalInput > 0 and is_on_wall():