Chaos_Kitchen/Scripts/PlayerControler.gd
2024-02-17 12:42:08 +01:00

39 lines
1.1 KiB
GDScript

extends CharacterBody2D
class_name Player
@onready var gridcontrol: TileMap = $"../NavigationMap"
var current_path : Array[Vector2i]
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _physics_process(delta):
if current_path.is_empty():
return
var target_position = gridcontrol.map_to_local(current_path.front())
global_position = global_position.move_toward(target_position, 5)
if global_position == target_position:
current_path.pop_front()
func _unhandled_input(event):
var click_position = get_global_mouse_position()
if event.is_action_pressed("move_to"):
if gridcontrol.is_spot_walkable(click_position):
current_path = gridcontrol.astar.get_id_path(
gridcontrol.local_to_map(global_position),
gridcontrol.local_to_map(click_position)
).slice(1)
signal can_interact(object : String)
func _on_can_interact(Interact_Type: String, object : Interactible):
prints("yippie", Interact_Type)