matter-js icon indicating copy to clipboard operation
matter-js copied to clipboard

Error causes physics to speed up and collisions stop working

Open lafkpages opened this issue 1 year ago • 5 comments

I'm working on this game and there's a bug that happens sometimes which causes this error to happen in the console:

Basically this error happens when a non-static body collides with a static one.

How to reproduce

At first I didn't know what caused it but now I found a way to make this error:

  1. Open my game
  2. Go into creative mode
  3. Turn on static in the bottom right corner
  4. Drop a few static blocks
  5. Turn off static in the bottom right corner
  6. Drop a non-static block on top of a static one

That causes the error to appear in the console. It also makes all of the physics run faster and collisions stop working. Also sometimes the static body and the non-static body that collided disappear.

lafkpages avatar Jul 22 '22 13:07 lafkpages

Are you able to share a minimal code case for this one? Thanks.

liabru avatar Nov 21 '22 22:11 liabru

I don't really know why it even happens, and I've tried to replicate it but I can't. I can only get it to happen in my game, which has a lot of irrelevant code. But I'll keep looking...

lafkpages avatar Nov 24 '22 11:11 lafkpages

I encountered the same issue. Did you solve it later?

z384647062 avatar May 23 '23 03:05 z384647062

Nope, issue still exists.

lafkpages avatar May 23 '23 07:05 lafkpages

In my case, the error was caused by setting the radius of a high-precision floating-point value for a Cricle Body. So I add Math.round and it works fine.

// radius = 1.123456789...
Math.max(Math.round(radius), 1)

z384647062 avatar May 23 '23 07:05 z384647062