Skip to content
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

collisionStart firing multiple times #366

Open
dxu opened this issue Feb 8, 2017 · 9 comments
Open

collisionStart firing multiple times #366

dxu opened this issue Feb 8, 2017 · 9 comments

Comments

@dxu
Copy link

dxu commented Feb 8, 2017

Hi! I wrote up a small plugin for adding collision events to bodies, but I'm looking to use this elsewhere, and I'm noticing that the 'collisionStart' event is being fired a lot of times compared what I would expect is a single collision between two boxes.

You can run the example included in the repo, but essentially I have two squares, BoxA and BoxB, falling onto the ground at different heights. I expected that there would be 3 collisionStart's (and 3 corresponding collisionEnd's), while there might be a bunch of collisionActive's:

  1. BoxA hits Ground
  2. BoxB hits BoxA (BoxB is above BoxA)
  3. BoxB falls over, hits Ground.

But instead I get something along the lines of 10-20 collisionStarts and Ends.

untitled

Is this intentional / expected? Am I doing something wrong?

Thanks for the great work you've done with this engine! It's really awesome, and I'm looking forward to playing with it further!

@dxu
Copy link
Author

dxu commented Feb 10, 2017

ah, never mind. I noticed that there is a unique pairID for collisions between two objects, so I can differentiate collisions based off that, I'm guessing?

So are new collisionStarts just any time there is a collision between two objects with a new contact point?

@liabru
Copy link
Owner

liabru commented Feb 13, 2017

I've not yet had chance to look into this - did you resolve it or was it a misunderstanding? Collision start should only really fire once for each pair, until the body moves out of contact.

@dxu
Copy link
Author

dxu commented Feb 14, 2017

Oh, sorry! I thought I was just misunderstanding how the collisions were supposed to work. So if a box lands on its corner (assuming 0 restitution), and then falls flat onto the ground, collisionStart should only fire once in that case?

I'll reopen in case I'm misunderstanding my misunderstanding.

@dxu dxu reopened this Feb 14, 2017
@liabru
Copy link
Owner

liabru commented Feb 14, 2017

Yeah it should fire once, then multiple collisionActive then finally collisionEnd. Can you share your test case?

@dxu
Copy link
Author

dxu commented Feb 18, 2017

Here were the examples I was testing with, I console.log the events.

Only collisionStart
Only collisionEnd
Only collisionActive
All events

I get ~9-15 collisionEnd events (seems to be inconsistent across refreshes), ~12-17 collisionStart events

@liabru
Copy link
Owner

liabru commented Feb 18, 2017

Thanks for this, will check it out.

@gokadi
Copy link

gokadi commented Jan 25, 2022

Hi! I faced the same issue. Are there any updates?
"matter-js": "^0.17.1",

The behaviour is the same as @dxu provided above. Although two bodies already started collision (in my case moving through each other), for some reason I receive several groups of (1 collisionStart, lots of collisionActive and 1 collisionEnd) events, but I assume it is expected as 1 group of these events.

@liabru
Copy link
Owner

liabru commented Feb 25, 2022

@gokadi can you check Matter.version is it 0.18.0?

If so can you try out the alpha build file included this PR? #1079

Be great to know if it resolves, here's the discussion on it #1077

@RandomGamingDev
Copy link

Hi! I faced the same issue. Are there any updates?
The same issue is happening to me on 0.19.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants