PolygonCollider2D colliding/intersecting

,


Hello, I’ve gotten pretty far by myself so far, but I have no answers for how to fix this, lots of red because of colliding/intersecting lines. So I have an array filled with Vector2 points for a PolygonCollider2D. Even if I try to make the points exist only on the outside they will still go to 0,0,0 probably because the array is filled with 0,0,0 points (If It’s possible to delete them then I’ll be happy and do that). In the image above all points where triangles vertices exist have a point on them.

example for single node set (same as the mesh):

pointies[(i * (28 * organismMutations.symmetry)) + 4] = verties[(i * (28 * organismMutations.symmetry)) + 1];
                    pointies[(i * (28 * organismMutations.symmetry)) + 5] = verties[(i * (28 * organismMutations.symmetry)) + 1] + new Vector3(Mathf.Cos(organismMutations.rotation[0] + ((((Mathf.PI * 2) / organismMutations.symmetry) * i))), Mathf.Sin(organismMutations.rotation[0] + ((((Mathf.PI * 2) / organismMutations.symmetry) * i))));
                    pointies[(i * (28 * organismMutations.symmetry)) + 6] = verties[(i * (28 * organismMutations.symmetry)) + 1] + new Vector3(Mathf.Cos(-0.1f + (organismMutations.rotation[0] + (((Mathf.PI * 2) / organismMutations.symmetry) * i))), Mathf.Sin(-0.1f + (organismMutations.rotation[0] + (((Mathf.PI * 2) / organismMutations.symmetry) * i))));
                    pointies[(i * (28 * organismMutations.symmetry)) + 7] = verties[(i * (28 * organismMutations.symmetry)) + 1];

Thank you for your possible help :).

What exactly do you want the end result to look like? The only clue I have is the name “organismMutations” in your code.

From the picture, it seems like you’re trying to make something pretty complex. Try making the simplest part of this “organism” possible–a single arm, tentacle, whatever–and see if that works. If it doesn’t, that needs to be solved before getting more complex. If it does work, keep progressing to more complex shapes. Test constantly, and stop to fix things as soon as they break. Especially when you’re new, this is the best way to develop complex systems.

Also, please use code tags whenever you post code on the forums. My eyes just skim over what you pasted above because of how difficult it is to read.

Fixed the code part. What I’m trying to do in the post is draw polygons on each vertex so creatures collide. what I’ve chosen to do now is draw around the creature if this doesn’t work. but since they spin each node except the center, they will inevitably collide polygons and give me deleted polygons. Right now I’m just drawing triangles and using a composite collider with a box collider, but now also that isn’t working and I don’t know why (they aren’t merging). There are 4 main body plan types “Shelled”, “Worms”, “Bilaterals”, and “Radials”. Everything else is the nodes rotating.

All I can see above are (very!) pretty pictures that don’t really explain it much (to me at least) and don’t show the actual colliders or at least you don’t describe them; just the visuals. I also don’t understand if these are dynamically animating i.e. you are trying to deform the colliders in realtime or not but if they are, you’re about as far from what a PolygonCollider2D wants to be as you can get. I mean, the above is not a polygon but lots and lots of them. I’m going to ignore the composite stuff because it’s likely related to the input polygons being fed to it. If you using the PolygonCollider2D with lots of paths then you need to be careful of consistent polygon winding directions.

I am interested in seeing if we can get you moving forward again though.

I am not sure if using a beta version of Unity is an option for you or not or if this is all experimental but it seemed appropriate to bring to your attention the new CustomCollider2D which was created for the very thing you’re trying to create above. A collider that allows you to explicit assign primitive collider shapes and change them in realtime.

This landed in 2021.2 which is currently in beta. A post here about that.

Here’s some experimental dev videos of mine showing you some of its flexibility to dynamically update in realtime:

Woah, yeah this seems exactly what I need especially the second. Thank you so much! I’ll see if I can get the beta there. the structure’s look is static btw. every node once set is set so they don’t spin or anything like that. I’m using the colors for something else in the future (closer to a certain color more like a type ex: red would be more carnivorous or something and green would be more plant-like). RGB colors are in a cube so if you want to average colors too average = sqrt(RGB1^2 +RGB2^2… / amount of RGBS) you have to add the squares of each color type (R.G.B) together before dividing then sqrt.

1 Like