31 lines
780 B
GDScript
31 lines
780 B
GDScript
extends CharacterBody2D
|
|
|
|
const SPEED = 200.0
|
|
const JUMP_VELOCITY = -300.0
|
|
const COYOTE_TIME_THRESHOLD = 0.1
|
|
const JUMP_BUFFER_TIME_THRESHOLD = 0.1
|
|
|
|
var direction = Input.get_axis("left", "right")
|
|
var coyote_timer = 0.0
|
|
var jump_buffer_timer = 0.0
|
|
|
|
@onready var sprite = $Sprite2D
|
|
@onready var statemachine = $StateMachine
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
if is_on_floor():
|
|
coyote_timer = COYOTE_TIME_THRESHOLD
|
|
elif coyote_timer > 0:
|
|
coyote_timer -= delta
|
|
|
|
if jump_buffer_timer > 0:
|
|
jump_buffer_timer -= delta
|
|
if Input.is_action_just_pressed("jump"):
|
|
jump_buffer_timer = JUMP_BUFFER_TIME_THRESHOLD
|
|
|
|
if Input.is_action_pressed("left"):
|
|
sprite.flip_h = true
|
|
if Input.is_action_pressed("right"):
|
|
sprite.flip_h = false
|
|
print(statemachine.current_state)
|