How to prevent Polygon Collider 2D from being concave

Hi when I make an shape with Polygon Collider 2D lines go inside the shape how can I prevent that.8976817--1234522--hey.png

The thread title is a little confusing; it’s your responsibility to ensure your outline is convex if that’s what you want. The “line” shown doesn’t make it concave.

The gizmo (lines) show you the physics shapes that any Collider produces. There are only 4 primitive shapes: circle, capsule, polygon and edge. Primitive polygons can only have 8 sides and be convex. The above doesn’t look like a real example as the utility that decomposes the path outlines for the PolygonCollider2D should, in theory, produce a single shape there as it only has 6 sides and is already convex so will produce a single shape.

Note that if the above was real, you’d see the Shape Count as 2 in the inspector for Collider2D > Info.

Ignoring all the above, it makes little to no difference to the collision detection or physics so maybe it’s worth explaining what the actual issue is you might be seeing.

1 Like

So it doesn’t matter if it’s convex or concave for physic system. I didn’t see any problem i just want it to be convex i dont like concaves.It is not concave actually i mean the line that goes inside the shape . When i move the corner this happens
8978761--1235107--Sprite-0001.png
8978761--1235110--2.png

What’s to say beyond you’re creating a concave outline which means it has to be composed of two convex polygons. Maybe you didn’t follow what I put originally?

I mean, look at the vertex in the middle bottom. That makes it concave.

You’re not really explaining what the problem is here. You seem to be suggesting that Unity is making this concave when it’s actually you doing that. If you don’t want that vertex in the middle then delete it. Beyond that, Please explain what the specific issue is.

I dont want the line that i am showing on the second 5.

https://www.youtube.com/watch?v=MNMDhjhNz0c

I have no idea what that statement means. Please explain in more detail what the problem is or I won’t be able to help you. I cannot keep guessing at what you want.

I dont want any line inside of my shape

I’ve already explained what the line is, I cannot explain it further.

But i dont want it isnt there any way

There’s a language barrier here; I’m not following what you need and you’re not following my explanations.

there is no barrier i understand what you are saying. But what i am saying is concave or convex don’t matter i dont want any line inside of my shape did you watch the video. Lines are appearing inside of the shape

But I explained all that in my posts above.

I came here with the same question. Kader, your question makes sense, it’s just your terminology was wrong, and unfortunately the supposed helper preferred to bludgeon you with that instead of getting the heart of the issue. I don’t know the geometry terminology either, and I’m sure everyone will be very polite about it.

I was trying to create a camera world boundary using a polygon collider 2D. It needed to be quite big and every time I adjusted it, it would create one of those “cross beams” Kader highlighted. It was a problem as those “cross beams” acted like boundaries. I don’t quite understand what was triggering those as I changed the shape of the collider.

Nonetheless, for whomever comes after me here, I solved it by: expanding the Points>>Paths>>Elements section of the collider, and then finding and deleting the array element “cross beam” as they appeared as I edited the sides of the polygon.

Being as I wrote all of 2D physics, I was trying to understand what the dev wanted and I help devs on the forums each and every day. Not understanding what the dev wanted and getting to the root of their misunderstanding of how the PolygonCollider2D works isn’t a “bludgeon”.

They are NOT “cross beams”, they are outlines to the shapes the PolygonCollider2D is creating. Look at the inspector for the collider, it shows you the shape-count. 2D physics (Box2D) can only produce convex polygons with up to 8 sides. The PolygonCollider2D allows you to create any outline including concave outlines and in doing so, it has to decompose that outline (which itself isn’t a valid thing physics can use) into multiple convex polygons. Your “cross beam” is just an edge where two of those shapes produced meet.

Changing the outline to be convex might remove certain shapes yes but it’s not a general solution to a problem.