-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add body, is it colliding? #478
Comments
Try this: var collision = Matter.SAT.collides(bodyA, bodyB);
if (collision.collided) {
// do something
} Where Actually, this might be a nice addition to |
Shamelessly stealing code, I created a routine that returns intersecting (colliding) bodies given a body and a filter. I use this to detect drag/drop collisions, but also to display intersections among bodies.
|
I spent today creating a prototype of a pull request which would implement my collidingBodies idea. I want to make it efficient, so I want to leverage broadphase to narrow down the bodies to test. I created a Grid.findBodies call to return all the bodies in buckets within a given bounds. And then I wrote a routine in my own application that would loop through these bodies and return In a "real" pull request I would generalize this more. Although I'm happy to create a pull request, in studying your existing independent modules it is not clear where a routine such as mine would make sense. Any module I choose seems to introduce a new unnatural dependency for that module. So my question is: would such a routine make sense in matterjs? Or should I just keep it in my codebase?
|
Can you put this in a jsfiddle giving an example of it working? Then I can get my head around it better! |
Hey so I managed to check for collisions by using the Bounds.overlaps function. See example below: .... This example is not perfect as it is intended to be used with circular objects, but you guys get the idea. |
Looked around but don't see an easy way to do this. When adding a body to the world, is there a way to easily ask if that body is "on top" (colliding with) any existing body? Tried to process "collisionStart/End" but it looks like those happen only as bodies move around.
Two additions:
So comments would be welcome, otherwise you can close this issue. Thanks.
The text was updated successfully, but these errors were encountered: