- Home /
Concave PolygonCollider2D
I'm making a 2D grid based platformer and I need to generate colliders based off the terrain data.
I can't just use a BoxCollider2D for each grid space that contains a platform because the corners of the boxes collide with the player and cause them to bump rather than move smoothly across the surface.
So I've come up with a way to generate a polygon collider that matches the platform's shape perfectly, but I've run into a problem.
The problem occurs when the entire platform is convex (I don't mean the shape contains convex parts, that's fine, I mean when the entire platform forms a convex shape). For example:
Imagine a large square level filed with air in every call except for the edges, which are all platforms.
If you were generating a 3D MeshCollider, you would give it a quad for the floor (facing up), a quad for the right wall (facing left), a quad for the roof (facing down) and a quad for the left wall (facing right). The result would be a bounding box to keep everything inside the level.
But to make a PolygonCollider2D, all you have to do is specify the points. So you give it the bottom left, bottom right, top right and top left. The problem is that it interprets those points as a convex shape and makes a square out of them rather than an inside-out bounding box type shape.
I'm trying to come up with a more complex terrain generation algorithm that takes this problem into account, but I would really appreciate any help people can give.
Your answer
![](https://koobas.hobune.stream/wayback/20220613123044im_/https://answers.unity.com/themes/thub/images/avi.jpg)