@@ -27,13 +27,13 @@ func _ready():
2727
2828# Click and Shift force the start and end position of the path to update
2929# and the node to redraw everything
30- func _input (event ):
31- if event .is_action_pressed ('click' ) and Input .is_key_pressed (KEY_SHIFT ):
32- # To call the setter method from this script we have to use the explicit self.
33- self .path_start_position = world_to_map (get_global_mouse_position ())
34- elif event .is_action_pressed ('click' ):
35- self .path_end_position = world_to_map (get_global_mouse_position ())
36-
30+ # func _input(event):
31+ # if event.is_action_pressed('click') and Input.is_key_pressed(KEY_SHIFT):
32+ # # To call the setter method from this script we have to use the explicit self.
33+ # self.path_start_position = world_to_map(get_global_mouse_position())
34+ # elif event.is_action_pressed('click'):
35+ # self.path_end_position = world_to_map(get_global_mouse_position())
36+
3737
3838# Loops through all cells within the map's bounds and
3939# adds all points to the astar_node, except the obstacles
@@ -82,7 +82,8 @@ func astar_connect_walkable_cells(points_array):
8282 # Note the 3rd argument. It tells the astar_node that we want the
8383 # connection to be bilateral: from point A to B and B to A
8484 # If you set this value to false, it becomes a one-way path
85- astar_node .connect_points (point_index , point_relative_index , true )
85+ # As we loop through all points we can set it to false
86+ astar_node .connect_points (point_index , point_relative_index , false )
8687
8788
8889# This is a variation of the method above
@@ -110,7 +111,18 @@ func calculate_point_index(point):
110111 return point .x + map_size .x * point .y
111112
112113
113- func recalculate_path ():
114+ func get_path (world_start , world_end ):
115+ self .path_start_position = world_to_map (world_start )
116+ self .path_end_position = world_to_map (world_end )
117+ _recalculate_path ()
118+ var path_world = []
119+ for point in _point_path :
120+ var point_world = map_to_world (Vector2 (point .x , point .y )) + _half_cell_size
121+ path_world .append (point_world )
122+ return path_world
123+
124+
125+ func _recalculate_path ():
114126 clear_previous_path_drawing ()
115127 var start_point_index = calculate_point_index (path_start_position )
116128 var end_point_index = calculate_point_index (path_end_position )
@@ -158,7 +170,7 @@ func _set_path_start_position(value):
158170 set_cell (value .x , value .y , 1 )
159171 path_start_position = value
160172 if path_end_position and path_end_position != path_start_position :
161- recalculate_path ()
173+ _recalculate_path ()
162174
163175
164176func _set_path_end_position (value ):
@@ -171,4 +183,4 @@ func _set_path_end_position(value):
171183 set_cell (value .x , value .y , 2 )
172184 path_end_position = value
173185 if path_start_position != value :
174- recalculate_path ()
186+ _recalculate_path ()
0 commit comments