You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Okay maybe i'm doing something wrong but i'm building 2 polygon's and i want to detect wether the second shape is not colliding anymore with the first shape.
I found the collision would treat the first polygon using it bounds shape instead of the real shape. So it still treats the first polygon as a box shape instead of the L shape i'm building.
Setup for the first polygon is a shape
new Polygon(new Vector(), [
new Vector(185,0),
new Vector(185,160),
new Vector(0,160),
new Vector(0,270),
new Vector(500,270),
new Vector(500,0),
new Vector(185,0),
]);
Setup for the second polygon, that can move around
new Polygon(new Vector(mouseposition.x, mouseposition.y), [
new Vector(-object.width, -object.height),
new Vector( object.width, -object.height),
new Vector( object.width, object.height),
new Vector(-object.width, object.height)
]);
Testing the collision
function isWithinBounds(objectPolygon, roomPolygon) {
return testPolygonPolygon(objectPolygon, roomPolygon)
}
Visual representation what is happening. The object is clearly 'outside' the other polygon but it's still detecting collision. I'm using Pixijs to draw the polygon's i get using 'drawPolygon' and passing the polygon.points.
The text was updated successfully, but these errors were encountered:
Collisions uses the Separating Axis Theorem (SAT) for its narrow-phase collision tests. One caveat to SAT is that it only works properly on convex bodies.
So knowing what the limitations where i used a different library to decompose my Polygon into different convex bodies. Then looping the polygons and test for collision
const decomposedPolygons = decomposePolygon(roomPolygon.points);
for (let i = 0; i < decomposedPolygons.length; i++) {
if (testPolygonPolygon(objectPolygon, decomposedPolygons[i])) {
return false; // Collision detected, object is in bounds
}
}
Okay maybe i'm doing something wrong but i'm building 2 polygon's and i want to detect wether the second shape is not colliding anymore with the first shape.
I found the collision would treat the first polygon using it bounds shape instead of the real shape. So it still treats the first polygon as a box shape instead of the L shape i'm building.
Setup for the first polygon is a shape
Setup for the second polygon, that can move around
Testing the collision
Visual representation what is happening. The object is clearly 'outside' the other polygon but it's still detecting collision. I'm using Pixijs to draw the polygon's i get using 'drawPolygon' and passing the polygon.points.
![debug](https://private-user-images.githubusercontent.com/37139936/237895019-d2fe3345-9729-4105-b8f3-2d8dc8b8ef23.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQxMTI2NjUsIm5iZiI6MTcyNDExMjM2NSwicGF0aCI6Ii8zNzEzOTkzNi8yMzc4OTUwMTktZDJmZTMzNDUtOTcyOS00MTA1LWI4ZjMtMmQ4ZGM4YjhlZjIzLmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIwVDAwMDYwNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFkOTllOTNjMGQ1NmJkZDQ1OWU5MDg5NjQyZDBhMWY2NjdlYzRjOTIyZGYyMjBlYmI2NDIxNDUxNzRlZWQ1YTgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.U_U0zlqPaQHfmzpKv9B0mOzcpIgW7PvfUsMQe1z8RWM)
The text was updated successfully, but these errors were encountered: