24 lines
814 B
GDScript
24 lines
814 B
GDScript
extends State
|
|
|
|
|
|
func physics_update(delta: float) -> void:
|
|
if not player.is_on_floor():
|
|
player.velocity += player.get_gravity() * delta
|
|
|
|
var direction := Input.get_axis("left", "right")
|
|
if direction:
|
|
player.velocity.x = move_toward(player.velocity.x, direction * player.SPEED, player.SPEED * 15 * delta)
|
|
#player.velocity.x = direction * player.SPEED
|
|
else:
|
|
player.velocity.x = move_toward(player.velocity.x, 0, player.SPEED * 5 * delta) # Decelerate to a stop
|
|
player.move_and_slide()
|
|
player.sprite.play("run")
|
|
|
|
if player.jump_buffer_timer > 0:
|
|
if player.is_on_floor() or player.coyote_timer > 0:
|
|
state_machine.transition_to("Jump")
|
|
elif not player.is_on_floor() and player.velocity.y > 0:
|
|
state_machine.transition_to("Fall")
|
|
elif player.velocity.x == 0:
|
|
state_machine.transition_to("Idle")
|