func _apply_movement():
var was_on_floor = is_on_floor()
velocity.y = move_and_slide_with_snap(velocity, snap, Vector2.UP, true).y
if is_on_floor(): # && was_on_floor: #&& player_state == 'fall':
coyote_timer.start(0.25)
func snap_to_floor():
self.snap = Vector2.DOWN * 100 # Vector(0,100) Snaps player to floor
# Keep this 100 or player will clip through floor
func disable_snap_to_floor(): # used for rising elevator
self.snap = Vector2(0,0)
func _apply_gravity(delta):
velocity.y += gravity * delta
func _handle_move_input():
var move_direction = -int(Input.is_action_pressed("ui_left")) + int(Input.is_action_pressed("ui_right"))
velocity.x = lerp(velocity.x, move_speed * move_direction, _get_h_weight())
if Input.is_action_just_pressed("ui_up"):
if is_on_floor() or not $coyoteTimer.is_stopped(): # if coyoteTimer is playing
coyote_timer.stop()
jump()
else:
# handles jump buffering
jump_buffer.start()
func _get_h_weight():
return 0.2 if is_on_floor() else 0.1
func jump():
disable_snap_to_floor()
velocity.y = jump_height