Full controle tactile et souris

This commit is contained in:
Thomas
2025-03-29 11:34:41 +01:00
parent be1ef5d71c
commit 2125236638
8 changed files with 81 additions and 84 deletions

View File

@@ -1,4 +1,5 @@
extends Node2D
class_name HumanPathFinder
var astar_grid: AStarGrid2D
var toFollow: Array[Vector2i]
@@ -14,9 +15,9 @@ func _ready() -> void:
astar_grid = AStarGrid2D.new()
astar_grid.region = world.get_used_rect()
astar_grid.cell_size = Vector2(48, 48)
astar_grid.diagonal_mode = AStarGrid2D.DIAGONAL_MODE_NEVER
astar_grid.default_compute_heuristic = AStarGrid2D.HEURISTIC_EUCLIDEAN
astar_grid.default_estimate_heuristic = AStarGrid2D.HEURISTIC_EUCLIDEAN
astar_grid.diagonal_mode = AStarGrid2D.DIAGONAL_MODE_AT_LEAST_ONE_WALKABLE
astar_grid.default_compute_heuristic = AStarGrid2D.HEURISTIC_CHEBYSHEV
astar_grid.default_estimate_heuristic = AStarGrid2D.HEURISTIC_CHEBYSHEV
astar_grid.update()
# only take into account the tiles that are marked with a navigation layer for cars
@@ -33,9 +34,14 @@ func _ready() -> void:
astar_grid.set_point_solid(tile_position)
else:
astar_grid.set_point_solid(tile_position)
for obstacles in world.obstacles:
if obstacles.get_cell_tile_data(tile_position) != null and obstacles.get_cell_tile_data(tile_position).get_collision_polygons_count(0):
if (obstacles.get_cell_tile_data(tile_position) != null and
obstacles.get_cell_tile_data(tile_position).get_collision_polygons_count(0)):
astar_grid.set_point_solid(tile_position)
#TODO find if the world cell is matching a semaphore pylon
func _process(delta: float) -> void:
if !controled:
@@ -50,7 +56,7 @@ func _process(delta: float) -> void:
var points = astar_grid.get_id_path(
world.local_to_map(world.to_local(my_global_position)),
world.local_to_map(world.to_local(target_global_position))
).slice(1, -1)
).slice(1)
if !points.is_empty():
toFollow = points