Generating Collision Shape from polyline

Godot Version

v4.3 dev4


I’m making a drawing physics line mechanic like in Crayon Physics.

I’m using Geometry2D.offset_polyline() to generate collision polygon from mouse input.

Problem is when I draw looping shape it returns 2 polygon which is outer one and inner hole,
since CollisionPolygon2D doesn’t support holes i need to somehow merge it into single polygon.

my current shape generation code

func update_shape(line: PackedVector2Array) -> void:
	var polygons := Geometry2D.offset_polyline(line, line_size, Geometry2D.JOIN_ROUND)

	polygon = polygons[0]

	center_of_mass = calculate_center(polygon)
	mass = polygon.size() as float * weight_mult

which results

Any ideas?

1 Like

nvm, I solved it with adding circles every mouse motion,
sounds stupid but it is much faster.