0 votes

I'm trying to identify cells in a TileMap that does not have a collisionshape, and are also in-between cells that do have collisionshapes in order to flag them as entry points.

The code seems to do what it should, but Godot seem to give me an error if the shape count is 0. Is there a better way to go about this or am I misunderstanding the error?

E 0:00:00.467 tilegetshapecount: Condition "!tilemap.has(pid)" is true. Returned: 0
<C++ Source> scene/resources/tile
set.cpp:745 @ tilegetshapecount()
Room.gd:30 @ check
Room.gd:18 @ identify
Room.gd:7 @ _ready()


onready var floor_map = $Floor
onready var point_map = $Points

func _ready() -> void:

func identify_entry_cells():
    var used_cell_positions = floor_map.get_used_cells()
    for cell_position in used_cell_positions:
        var is_wall = check_is_wall(cell_position)

        # If current cell does not have a shape, check adjacent cells
        if !is_wall:
            var left_offset = check_is_wall(Vector2(cell_position.x - 1, cell_position.y))
            var right_offset = check_is_wall(Vector2(cell_position.x + 1, cell_position.y))
            var up_offset = check_is_wall(Vector2(cell_position.x, cell_position.y - 1))
            var down_offset = check_is_wall(Vector2(cell_position.x, cell_position.y + 1))

            # If adjacent cells on both sides have shapes, current cell is an entry cell
            if left_offset and right_offset:
                # Add a tile above current tile to vizualise entry cell
                point_map.set_cellv(cell_position, 0)

            elif up_offset and down_offset:
                point_map.set_cellv(cell_position, 0)

func check_is_wall(cell):
    var tile_id = floor_map.get_cellv(cell)
    var tile_shapes = floor_map.tile_set.tile_get_shape_count(tile_id)
    if tile_shapes == 0:
        return false
        return true
asked May 3 in Engine by Caj Michael Andersso (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.