How to optimize 2D polygon colliders in a Unity top down game

Polygon colliders are great for when you can’t just slap a circle or a box onto something, and we use it a lot in our hand drawn levels. However, Unity’s autogenerated polygon colliders are a bit too complex, leading to issues where the player can get stuck when moving on what seems to be a simple shape.

Using the simple but very smart PolygonColliderSimplification component (script below), you can easily simplify your Polygon Collider 2D and Edge Collider 2D to have less points, which leads to more accurate collision detection and possibly better performance.

It helped me fix “getting stuck” issues where my player’s Box Collider 2D got stuck in areas which didn’t seem logical to get stuck at. After some tips from fellow devs, I was told to use a Capsule collider 2D instead of a box collider, but just fixing the colliders solved so many problems, so I guess a combination of this and a capsule collider should work great.

I found the script from the user j-bbr on Github, download it here: 
https://github.com/j-bbr/PolygonColliderSimplification

If it helped you, follow @bluegoogames for more tutorials, devlogs and gameplay from our upcoming game Space Chef. Or check our Instagram if that’s your thing. 

Previous
Previous

How to make 2D cel shaded and outlined smoke