Godot Version
4.3
Question
Hey, anyone know how to combine collision polygons. I have some collision polygons being created by tiles and I want to combine them into one polygon using merge_polygons, but the combined polygon is not correct.
In the image the larger teal polygon is a few tile collision boxes next to each other. The smaller rectangle on the top right is my attempt at combining them with merge_polygons.
Here is the code:
# create new collision polygon
var new_collision_polygon: PackedVector2Array = PackedVector2Array()
for cell in get_used_cells():
var parent_tile_data: TileData = parent_layer.get_cell_tile_data(cell)
# merge parent's collision polygon with new collision polygon
var parent_poly: PackedVector2Array = parent_tile_data.get_collision_polygon_points(0, 0)
new_collision_polygon = Geometry2D.merge_polygons(new_collision_polygon, parent_poly)[0]
# remove parent tile data's collision polygon
# parent_tile_data.remove_collision_polygon(0, 0)
#set hurt collision polygon to our new combined collision polygon
print(new_collision_polygon)
var hurt_collision_polygon: ConvexPolygonShape2D = ConvexPolygonShape2D.new()
hurt_collision_polygon.set_points(new_collision_polygon)
hurt_collision_shape.set_shape(hurt_collision_polygon)
Any help appreciated!