I'm trying to generate collisions for a procedurally generated tileset using the TileSet.tile_add_shape
method (here). Unfortunately, it doesn't seem to be generating the collision shapes. I've been scraping google for any solutions, but it seems like not many people have encountered this error, so hopefully I'm just doing something wrong. I've attached a minimum viable project that could hopefully shed some light into what I'm doing, but essentially I have a class Internal2xTileSet
that is taking a texture and a bunch of Rect2
s that point to regions of that texture to create a tileset that I can use for doing my own autotiling with depth sensitive shading. My main loop that goes through these tile regions and creates tiles for them looks like this:
# shade and variant are can both be chalked up as variations of the same type of tile (i.e. corner tile, full tile, etc)
var id = tileset.get_last_unused_tile_id()
tileset.create_tile(id)
tileset.tile_set_tile_mode(id, TileSet.SINGLE_TILE)
tileset.tile_set_name(id, tile_type + "_" + str(shade) + "_" + str(variant))
tileset.tile_set_texture(id, TEXTURE)
# This is just using the Rect2s that I feed into the tileset creator to pull out the region of the texture
# Ultimately, this portion is working correctly and grabbing the texture, so I won't explain too much here
tileset.tile_set_region(id, Rect2(
Vector2(
region.position.x + x * tile_info["scale"],
region.position.y + y * tile_info["scale"]) * TILE_WIDTH,
Vector2.ONE * TILE_WIDTH * tile_info["scale"]))
# This is the area causing problems.
for i in tile_info["shapes"].size():
tileset.tile_add_shape(id, tile_info["shapes"][i], tile_info["shape_transforms"][i], ONE_WAY)
tile_dict[tile_id][shade].push_back(id)
Example definition for a tile:
export(Array, Rect2) var FULL_TILES
const PROFILES = {
"FULL": 15,
}
var full_tile_shape = ConvexPolygonShape2D.new().set_point_cloud(PoolVector2Array([
Vector2(0, 0),
Vector2(TILE_WIDTH, 0),
Vector2(TILE_WIDTH, TILE_WIDTH),
Vector2(0, TILE_WIDTH)
]))
"FULL_TILES": {
"id": PROFILES["FULL"],
"regions": FULL_TILES,
"scale": 1,
"shapes": [full_tile_shape],
"shape_transforms": [Transform2D.IDENTITY]
},
I have found this post, but it seems they find the solution and I wasn't able to discern what that was. I did see in there minimum_viable_project that they were able to generate collisions shapes, but I have no idea how there implementation of it differs from mine.