FantasyRun/character/character.gd

45 lines
892 B
GDScript3
Raw Normal View History

extends Area3D
class_name Character
signal turn(direction: String)
2024-10-12 16:16:43 -07:00
@export var speed: float = 20.0
@export var tile: Tile
var total_distance: float = 0.0
func _ready() -> void:
if tile == null or tile is not Tile:
printerr("tile is not set to a Tile")
return
2024-09-30 20:50:05 -07:00
func _process(delta: float):
if tile == null:
return
if Input.is_action_just_pressed("ui_right"):
turn.emit("right")
if Input.is_action_just_pressed("ui_left"):
turn.emit("left")
global_position = tile.marker_position
global_rotation = tile.marker_rotation
if tile.follow.progress_ratio >= 1:
return
2024-09-30 20:50:05 -07:00
var travel: float = speed * delta
tile.follow.progress += travel
total_distance += travel
2024-10-04 18:25:33 -07:00
func _on_area_entered(area):
if area is Obstacle:
handle_obstacle(area)
func handle_obstacle(obstacle: Obstacle) -> void:
2024-10-04 18:25:33 -07:00
if obstacle.effect == Obstacle.ObstacleEffect.Kill:
print("kill")
speed = 0