extends Area2D var overlapping_nodes: Dictionary = {} func _ready(): connect("body_shape_entered", Callable(self, "_on_body_shape_entered")) connect("body_shape_exited", Callable(self, "_on_body_shape_exited")) func get_overlapping_nodes(): for key in overlapping_nodes: var body = overlapping_nodes[key].body var body_shape: int = overlapping_nodes[key].body_shape var area_shape: int = overlapping_nodes[key].area_shape var body_shape2d: Shape2D = body.shape_owner_get_shape(body_shape, 0) var area_shape2d: Shape2D = shape_owner_get_shape(area_shape, 0) var body_shape2d_transform = body.shape_owner_get_owner(body_shape).get_global_transform() var area_shape2d_transform = shape_owner_get_owner(area_shape).get_global_transform() var collision_points = area_shape2d.collide_and_get_contacts(area_shape2d_transform, body_shape2d, body_shape2d_transform) overlapping_nodes[key].collision_points = collision_points if collision_points.size() == 2: overlapping_nodes[key].collision_points.append( overlapping_nodes[key].collision_points[0] + Vector2(0, 16) ) overlapping_nodes[key].collision_points.append( overlapping_nodes[key].collision_points[1] + Vector2(0, 16) ) return overlapping_nodes func _on_body_shape_entered(id, body, body_shape, area_shape): if body != null: #print("Id: ", id, " [", body, ", ", body_shape, ", ", area_shape, "] has entered. ") var key := str(id) + ":" + str(body_shape) overlapping_nodes[key] = { "body": body, "body_shape": body_shape, "area_shape": area_shape, "collision_points": [], } func _on_body_shape_exited(id, body, body_shape, area_shape): if body != null: #print("Id: ", id, " [", body, ", ", body_shape, ", ", area_shape, "] has exited. ") var key := str(id) + ":" + str(body_shape) overlapping_nodes.erase(key)