mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 23:10:08 +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:
committed by
Hugo Locurcio
parent
78dffe0d04
commit
648befbf58
@@ -23,4 +23,3 @@ texture = ExtResource("4")
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
offset = Vector2(576, 324)
|
||||
current = true
|
||||
|
||||
@@ -33,7 +33,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
|
||||
|
||||
@@ -16,9 +16,9 @@ dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.cte
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
|
||||
@@ -147,6 +147,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 = local_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 = local_to_map(world_start)
|
||||
self.path_end_position = local_to_map(world_end)
|
||||
|
||||
@@ -16,9 +16,9 @@ dest_files=["res://.godot/imported/character.png-eb70ac48a5acf508c4b7740ea4ac4fa
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
|
||||
@@ -16,9 +16,9 @@ dest_files=["res://.godot/imported/obstacle.png-0258c5f5ce65bfa0dd8610adeb784f54
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
|
||||
@@ -16,9 +16,9 @@ dest_files=["res://.godot/imported/path_end.png-02b79e25892cd8d863bd44c3c5a1720e
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
|
||||
@@ -16,9 +16,9 @@ dest_files=["res://.godot/imported/path_start.png-475bd0b469629aa8779d506c5134e5
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
|
||||
Reference in New Issue
Block a user