Godot Version
4.5.1
Question
How can I get my multiple tilemaplayers to sort of “combine” so my enemy using a navigationagent2d can move properly instead of making paths that go through walls and trying to follow them
I’ve tried things like this:
extends TileMapLayer
var _obstacles: Array[TileMapLayer] = []
func _ready() -> void:
_get_obstacle_layers()
func _get_obstacle_layers():
# make sure the name here is the same as the group's
var layers = get_tree().get_nodes_in_group("Obstacles")
for layer in layers:
if layer is not TileMapLayer: continue
_obstacles.append(layer)
func _use_tile_data_runtime_update(coords: Vector2i) -> bool:
return _is_used_by_obstacle(coords)
func _is_used_by_obstacle(coords: Vector2i) -> bool:
for layer in _obstacles:
if coords in layer.get_used_cells():
var is_obstacle = layer.get_cell_tile_data(coords).get_collision_polygons_count(0) > 0
if is_obstacle:
return true
return false
func _tile_data_runtime_update(coords: Vector2i, tile_data: TileData) -> void:
if not _is_used_by_obstacle(coords):
tile_data.set_navigation_polygon(0, null)
but it doesnt work I dont even get an error
i’ve tried following Pathfinding Guide for 2D Top-View Tiles in Godot 4.3 - casraf.dev but it doesnt seem to work in godot 4.5 or atleast I couldnt get it to.
My Scene looks a little like this, this is the tilemaplayers I need to “combine” or make pathbindable
Also the player can build on a grid (so they can place tiles on the BuildingLayer tilemaplayer node, so I need the Floor layer to update and remove tiles/add tiles in realtime to respond to that
thanks in advance for the help!
