replit / kaboom

💥 JavaScript game library
https://kaboomjs.com
MIT License
2.64k stars 225 forks source link

Circle Shape Collider #782

Open peratik opened 8 months ago

peratik commented 8 months ago

Hi,

How to add a circle shape collider?

I know area has a property for setting shape

But it seems circle colliders is not supported.

ganevdev commented 5 months ago

Yes, I have the same problem. https://kaboomjs.com/#AreaCompOpt - the documentation says that "currently only Rect and Polygon is supported".

Circle is not supported, but given that polygon is supported, I think you can just make the polygon in the shape of a circle.

mflerackers commented 2 months ago

The problem is that the SAT collision code only knows how to work with polygons. If this is fixed, circle areas can stay circle areas. To fix it, you need to add code to find the polygon point (not vertex, point) closest to the circle and take the orthogonal to the line connecting that point and the circle center as projection axis. To find the point quickly, you need Voronoi partitioning of the polygon.