Check for obstacle before teleporting player in Grid-based Pathfinding with Astar (#771)

Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
This commit is contained in:
dev-gilbride
2023-02-24 10:22:48 -07:00
committed by GitHub
parent ccc4354331
commit c8f0706055
2 changed files with 9 additions and 1 deletions

View File

@@ -34,7 +34,7 @@ func _process(_delta):
func _unhandled_input(event):
if event.is_action_pressed("click"):
var global_mouse_pos = get_global_mouse_position()
if Input.is_key_pressed(KEY_SHIFT):
if Input.is_key_pressed(KEY_SHIFT) and get_parent().get_node("TileMap").check_start_position(global_mouse_pos):
global_position = global_mouse_pos
else:
_target_position = global_mouse_pos

View File

@@ -127,6 +127,14 @@ func is_outside_map_bounds(point):
return point.x < 0 or point.y < 0 or point.x >= map_size.x or point.y >= map_size.y
func check_start_position(world_start):
var start_point = world_to_map(world_start)
if start_point in obstacles:
return false
return true
func get_astar_path(world_start, world_end):
self.path_start_position = world_to_map(world_start)
self.path_end_position = world_to_map(world_end)