Generating an invalid CollisionPolygon2D?

Godot Version



In this video, I create a polyline linking the two circle objects and move the objects around, creating changes in the curve. When the curve changes the collision polygon that surrounds the curve is also regenerated. I’ve turned on Debug->Visible Collision Shapes to better visualize what’s happening. In most positions the collision polygon generates with a rainbow of polygons and everything works as expected but in some positions no sub-polygons are generated for the collision polygon. This results in the line scene not triggering any collision events which is a bit of a problem.

My suspicion is that I’m somehow generating an invalid polygon but it looks fine and I don’t know what tools I can use to analyse that (do you?). Also it seems to be easier to make happen when the line is closer straight and the collision polygon just a rectangle with rounded ends.

One other thing I noticed that isn’t in the video, sometimes I can get a collision polygon that only has a single sub-polygon and that condition is often one pixel of movement away from an empty collision polygon. Not sure what that mean except maybe just that there are shapes that are perfectly convex without having to be split if the line is straight enough.

I found this topic which seems very close to my problem but moving the collision polygon regen to the _physics_process function didn’t make a difference.

I’m creating this CollisionPolygon2D’s polygon by shortening and Geometry2D.offset_polyline’ing a Curve2D like so.

var path : Curve2D =
func gen_collision_polygon(width, end_allowance):
	var short_path : PackedVector2Array = []
	var d1 : float
	var d2 : float
	for pt in path.get_baked_points():
		d1 = pt.distance_to(control_points[0])
		d2 = pt.distance_to(control_points[-1])
		if d1 > end_allowance and d2 > end_allowance:
	if short_path.size() < 2:
		return []
	var polygons = Geometry2D.offset_polyline(short_path, #path.get_baked_points(), 
	return polygons[0]

If more code or more pics would be helpful I’m more than happy to provide whatever is needed.