liabru / matter-js

a 2D rigid body physics engine for the web ▲● ■
MIT License
16.22k stars 1.95k forks source link

collision events not triggering half the time with many bodies #1234

Open FilterUnfiltered opened 11 months ago

FilterUnfiltered commented 11 months ago

I have a pretty big project that I have made with phaser and using matter as the physics engine. I have an issue where, despite the bodies bouncing normally, the event for the collision is never triggered. I have tried with start, active, and end, and none of them work. The issue only exists when there are many bodies on the screen.

michael-garofalo commented 3 months ago

That sounds like a problem I had before. I use Tumult Hype, which uses Matter.js as the Physics engine. I was having trouble detecting collisions. To solve the problem, I didn't just check for A-B collisions, I checked for B-A collisions too. If you have Hype, the template here…

https://photics.com/free-template-tuesday-34-tumult-hype-jump/

I'm not sure if that's the most optimal way to solve the problem, but the example game was playable after adding the additional collision checking.