Does CollisionPolygon2D support 9+ vertices?

I've tested CollisionPolygon2D on polygons with 3-16 vertices. Polygons with up to 8 vertices demonstrates pretty accurate collision; however, when the vertices exceeds 8 (like with a Nonagon, for instance), it seems only eight vertices are actually being registered. With a nonagon, one vertex is missing. With a decagon, two are missing (and so forth).

I know CollisionPolygon2D only supports convex polygons, but are Nonagons not? I believe it is as are all polygons with vertices [9-16]. I tried replacing CollisionPolygon2D with CollisionChain2D using the exact same vertices, but this gives unexpected (and weird) collision (the polygon never appears to rotate as it falls and hits other objects suggesting the collision is either very small or nonexistent).

I did get CollisionChain2D to work accurately on some concave polygons, but it never seems to work on regular convex polygons (like the Nonagon). Seeing as I've had little luck with either, I'm at an impasse as to which is more appropriate for the situation or if CollisionPolygon2D can be used for polygons with 9+ vertices at all.

This is how I setup collision for a Nonagon in C# :

var unit = 256/96f;
var _collisionShape2D = _node.CreateComponent();
_collisionShape2D.As().VertexCount = 9;
_collisionShape2D.As().SetVertex(0, new Vector2(-0.3515625f, -1.000000f) / 2 * unit);
_collisionShape2D.As().SetVertex(1, new Vector2(+0.3515625f, -1.000000f) / 2 * unit);
_collisionShape2D.As().SetVertex(2, new Vector2(+0.8593750f, -0.515625f) / 2 * unit);
_collisionShape2D.As().SetVertex(3, new Vector2(+1.0000000f, +0.140625f) / 2 * unit);
_collisionShape2D.As().SetVertex(4, new Vector2(+0.6250000f, +0.750000f) / 2 * unit);
_collisionShape2D.As().SetVertex(5, new Vector2(0000000000f, +1.000000f) / 2 * unit);
_collisionShape2D.As().SetVertex(6, new Vector2(-0.6250000f, +0.750000f) / 2 * unit);
_collisionShape2D.As().SetVertex(7, new Vector2(-1.0000000f, +0.140625f) / 2 * unit);
_collisionShape2D.As().SetVertex(8, new Vector2(-0.8593750f, -0.515625f) / 2 * unit);

If this were an Octagon, it would behave as expected; that ninth vertex doesn't appear to register (the eighth vertex connects with the first). If you try to replace CollisionPolygon2D with CollisionChain2D, the previous collision turns wonky and doesn't even behave as it did previously. Note, the objects in question are Sprite2D and have dimensions [256 pixels, 256 pixels]. In my project, 96 pixels = 1 world unit, hence why I multiple by 'unit'.

Documentation does not indicate any limitations. Anybody have conclusion on this?

Sign In or Register to comment.