mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 15:00:09 +01:00
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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user