Hello. I'm currently using clip_polygons_2d to take chunks out of polygons. I have a "miner" polygon that is offset to the cursor's position. Then, an area2D reads body collisions at that position and clips all of the polygons affected. Of course, the polygons and their collision shapes are updated afterwards. This works great, and it's exactly what I had intended, however, I can't seem to get the "detached" polygon to exist. It just immediately destroys itself after being disconnected. How would I go about keeping that "detached" polygon? I understand that the Geometry's "is_polygon_clockwise" method might be useful, but I do not know how to use that. As far as I know, Godot doesn't support internal vertexes, but please correct me if I'm wrong. (Static Bodies are just test subjects)
you need add a new staticbody2d. like this """
extends Node2D onready var collision_finder = $Area2D onready var miner = $Area2D/Miner export(PackedScene) var static_body_2d func _physics_process(delta): if Input.is_action_just_pressed("mouse_left"): collision_finder.global_position = get_global_mouse_position() func _on_Area2D_body_entered(body): var offset_poly = Polygon2D.new() var collided_poly = body.get_node("Polygon2D") var collided_collision_poly = body.get_node("CollisionPolygon2D") offset_poly.polygon = miner.global_transform.xform(miner.polygon) var res = Geometry.clip_polygons_2d(collided_collision_poly.polygon,offset_poly.polygon) if len(res)>0: collided_poly.polygon = res[0] collided_collision_poly.set_deferred("polygon", collided_poly.polygon) if len(res)>1: var j = 1 var len_res = len(res) while j<len_res: var cur_static_body_2d = static_body_2d.instance() add_child(cur_static_body_2d) cur_static_body_2d.get_node("Polygon2D").polygon = res[j] cur_static_body_2d.get_node("CollisionPolygon2D").set_deferred("polygon", res[j]) j+=1
"""
@"Bloody Spuddy Buddy"
Thank you so much! This is exactly what I needed, However, I've actually never worked with Packed scenes before so I'm unsure of how to properly set it up. Right now I get an error "Attempt to call function 'get_node' in base 'null instance' on a null instance." one your line 27. Could you please enlighten me on how to set up the PackedScene? Or am I doing something else wrong? Thank you.
@vmjcv
oh. Am I supposed to make a StaticBody2D scene with the appropriate children and then use that? I did that and it's working. Thank you for your time. If i'm using the Packed scene incorrectly then please let me know. Otherwise, this is solved.