how to add navigationObstacle2D to tile map

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Konishi

Recently I made a game about a zombie chase after the player, here is the problem. I use tilemap to create a maze, but it seems the zombie would not avoid the tile intentionally if tileset in the way of navigation.
Do you have any idea add some navigationObstacle2D to tile set

In godot 3.5, I’m not sure you can. However, the best way to achieve this is to add placeholders in the tileset that essentially mark a location where a developer can instance the NavigationObstacle2D (or any other node). Something like this:

func spawn_items():
    for cell in items.get_used_cells():
        var id = items.get_cellv(cell)
        var type = items.tile_set.tile_get_name(id)
        var pos = items.map_to_world(cell) + items.cell_size/2
        match type:
            'navigation_obstacle':
                var o = ObstacleScene.instance()
                o.position = pos
                add_child(s)
            'player_spawn':
                $Player.position = pos
            # other matches
     # rebuild navigation, etc...

spaceyjase | 2023-05-19 10:20