Prozi / detect-collisions

Points, Lines, Boxes, Polygons (also hollow), Ellipses, Circles. RayCasting, offsets, rotation, scaling, bounding box padding, flags for static and ghost/trigger bodies
https://prozi.github.io/detect-collisions/
MIT License
206 stars 22 forks source link

Only first polygon segment triggering collision between polygon and circle #15

Closed kevinoleary19 closed 2 years ago

kevinoleary19 commented 3 years ago

Thanks for your work on maintaining this package!

Running into a bit of a weird issue. Hopefully I'm missing something simple.

I've created a system where I am collision testing between a circle and different polygons. I've noticed that only the first set of points that I pass into the polygon are being 'collided' with by the circle. Here is a visual example of my data drawn through the canvas functionality provided by the library.

Screen Shot 2021-10-14 at 4 08 40 PM

In the image above, I'm passing in 3 points to the createPolygon method:

const points = [[1745, 4863], [1815, 3740], [1425, 3902]];
const polygon = system.createPolygon(undefined, undefined, points);

If I swap the first two coordinate pairs in the list, thus making the overlapping side the 'first' line of the polygon, the system correctly identifies the collision.

Also, If I remove one of the edges such that the polygon is now a line, it correctly identifies the collision, illustrated by the image below

Screen Shot 2021-10-14 at 4 08 29 PM

For each of the above changes I made, the bounding volume hierarchy is correctly identifying that this polygon is a potential, so that part of the system is fine for me.

This originally was happening to me with 4 sided polygons and though it may be related the shapes being concave, but I created the test triangle above to eliminate that as a cause.

Is it potentially that I am not passing in an x or y coordinate to the polygon? I'm using typescript and the type definitions mark those args as optional, so I was thinking that was not the cause either but could be wrong.

Any help would be much appreciated!

Prozi commented 3 years ago

please also provide the code for circle points and radius and scale will reproduce and tell you what i think

Prozi commented 3 years ago

@koleary94

Prozi commented 2 years ago

also try version 3+ and see if you get same error thanks

Prozi commented 2 years ago

@koleary94 assuming this works now after version 3+

closing the issue and feel free to reopen if you have more comments, or if I misunderstood something