Godot Version
Godot 4.6
Question
This is how I’m setting up the AStarGrid2D:
func _ready() -> void:
astar = AStarGrid2D.new()
astar.default_compute_heuristic = AStarGrid2D.HEURISTIC_MANHATTAN
astar.default_estimate_heuristic = AStarGrid2D.HEURISTIC_MANHATTAN
astar.cell_shape = AStarGrid2D.CELL_SHAPE_ISOMETRIC_DOWN
astar.cell_size = tile_map.tile_set.tile_size
astar.diagonal_mode = AStarGrid2D.DIAGONAL_MODE_NEVER
astar.region = tile_map.get_used_rect() #Rect2i -> (Vector2(posizione), Vector2(dimensione))
for tile_coord in tile_map.get_used_cells():
var t_data = tile_map.get_cell_tile_data(tile_coord)
if t_data and t_data.get_custom_data("obstacle"):
astar.set_point_solid(tile_coord)
astar.update()
Inside a Player node I call the get_point_path function:
I already made sure that it enters the state MOVING
func _input(event: InputEvent) -> void:
#print(event)
#STATUS -> TURNO ATTIVO
if _status:
#MOVIMENTO
if current_battle_state == battle_states.MOVING:
#print("Cambiato stato da IDLE a MOVING, selezione percorso")
#disegna la preview di movimento
if event is InputEventMouseMotion and not moving:
var tile_position: Vector2i = tilemap.local_to_map(get_global_mouse_position()) #Prende le coordinate del mouse
if tilemap.get_cell_atlas_coords(tile_position) != Vector2i(-1, -1) and target_tile != tile_position: #Controlla se la tile è non vuota ed evita di ricalcolare lo stesso percorso due volte
target_tile = tile_position
move_pts = grid.get_point_path(_current_tile, tile_position)
print(grid.get_point_position(tile_position))
if move_pts.size() > _movement:
var too_far_pts: PackedVector2Array = move_pts.slice(_movement, move_pts.size())
move_pts.resize(_movement+1)
too_far_path.points = too_far_pts
else:
too_far_path.clear_points()
path_preview.points = move_pts
SignalBus.emit_signal("mesuring_distance", move_pts.size(), _movement)
Did I mess up the setup for the AStarGrid2D?