extends Area3D class_name Character signal turn(direction: TileTurn.Direction) @onready var animation_player: AnimationPlayer = $AnimationPlayer as AnimationPlayer @export var speed: float = 20.0 @export var jump_height: float = 3 @export var tile: Tile var total_distance: float = 0.0 var current_height: float = 0.0 var jump_tween: Tween var fall_tween: Tween var in_air: bool = false var sliding: bool = false func _ready() -> void: animation_player.animation_finished.connect(_animation_finished) if tile == null or tile is not Tile: printerr("tile is not set to a Tile") return func _process(delta: float) -> void: if tile == null: return if Input.is_action_just_pressed("ui_right"): turn.emit(TileTurn.Direction.Right) if Input.is_action_just_pressed("ui_left"): turn.emit(TileTurn.Direction.Left) if Input.is_action_just_pressed("ui_up"): jump() if Input.is_action_just_pressed("ui_down"): slide() global_position = tile.marker_position global_rotation = tile.marker_rotation if tile.follow.progress_ratio >= 1: return var travel: float = speed * delta tile.follow.progress += travel total_distance += travel tile.follow.v_offset = current_height func _on_area_entered(area: Area3D) -> void: if area is Obstacle: handle_obstacle(area) func handle_obstacle(obstacle: Obstacle) -> void: if obstacle.effect == Obstacle.ObstacleEffect.Kill: print("kill") speed = 0 func jump() -> void: if in_air or sliding: return in_air = true jump_tween = get_tree().create_tween() jump_tween.tween_property(self, "current_height", jump_height, 0.25).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT) jump_tween.tween_callback(fall) func fall() -> void: fall_tween = get_tree().create_tween() fall_tween.tween_property(self, "current_height", 0, 0.25).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN) fall_tween.tween_callback(finish_falling) func finish_falling() -> void: in_air = false func slide() -> void: if in_air or sliding: return sliding = true animation_player.play("slide") func _animation_finished(animation_name: String) -> void: if animation_name == "slide": sliding = false