I see in the interface how unity detects the edges of my 2dsprite and sub divides it into triangles/ rectangles, is there a way i can get those polygons? It would be really useful so that I can manually check collisions.!
You need to use:
- PolygonCollider2D.GetTotalPointCount
- PolygonCollider2D.points
- PolygonCollider2D.pathCount
- PolygonCollider2D.GetPath
Now you can get the points in the paths and the paths itself and then construct the polygon collider using them.
You’ll have to use the GetPath and points of the PolygonCollider2D class, and use those to figure out the shape.
If you want a rougher check, you can use bounds to get a bounding box around the polygon collider.
Now, why would you want to do this? Just getting the collision from the normal physics system is easier and faster. No need to reinvent the wheel.