Adding pathing

This commit is contained in:
Dan 2024-06-01 19:29:26 +01:00
parent a91635a68c
commit 9f9f1a7502
5 changed files with 187 additions and 7 deletions

View file

@ -1,11 +1,33 @@
extends Node2D
class_name Glowling
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
@onready var tilemap = $"../TileMap" # This needs rectifying
var current_path : Array[Vector2i] = []
var speed : int = 10
func _ready():
$GlowlingAnimations.play("GlowingPulse")
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
if current_path.is_empty():
return
var target_position = tilemap.map_to_local(current_path.front())
global_position = global_position.move_toward(target_position, speed)
if global_position == target_position:
current_path.pop_front()
pass
## This is the temporary way for having something move
func _unhandled_input(event):
var click_position = get_global_mouse_position()
if event.is_action_pressed("move_to"):
if tilemap.is_point_walkable(click_position):
current_path = tilemap.astar.get_id_path(
tilemap.local_to_map(global_position),
tilemap.local_to_map(click_position)
).slice(1)