matterjs physics not behaving correctly

48 views Asked by At

In my game, I have a scenario where (simple) polygons are created dynamically in parts from vertices.

However, I am facing what appears to be a bug with the physics between these Polygons.

Take the below image of 2 polygons (showing vertices ordering via numbers).

Image of two polygons with vertices listed

I have recreated this example that shows a Polygon in two parts but when they collide together the behaviour is extremely strange, see the video below.

Video here

As you can see above, once the two polygons collide one is strangely thrown around.

Does anyone know what might be going on here? This is just one example but I have other polygons also facing the issue.

See below for a codepen recreation including all vertices used etc (using phaser + matter) and some additional information embedded in the pen.

Codepen Recreation

// vertices of both polygons
 verticesTop = [
    { x: 369.0465076788701, y: 608.8012502894586 },
    { x: 354.8784175468987, y: 556.2317484173886 },
    { x: 307.9626367720781, y: 552.119630436472  },
    { x: 317.73639223252496, y: 477.3301010610348 },
    { x: 244.85158210397867, y: 471.6025839265548 },
    { x: 268.09225309287183, y: 546.1738331583199 },
    { x: 235.62039320960963, y: 622.9079760483232 }
  ];

  verticesBottom = [
    { x: 235.62039320960963, y: 622.9079760483232 },
    { x: 369.0465076788701, y: 608.8012502894586 },
    { x: 387.9793648300112, y: 679.0500177789156 },
    { x: 211.9339970778227, y: 678.8812190919905 }
  ];
0

There are 0 answers