Matter-js: MatterJS and performance for a lot of Bodies.

Created on 17 May 2017  路  4Comments  路  Source: liabru/matter-js

Hello again, I still want to use matterJS for a 2D game with a LOT of blocks.

Right now to add 50000 parts to an object, It takes nearly 40 seconds, is there anything it can do to boost the performances or should I consider using something else for my game haha !

I would have loved having a realistic physics engine in the game, but maybe it's too slow... :'(

question

Most helpful comment

I'd challenge _any_ JavaScript physics engine to cope with 50,000 bodies!

All 4 comments

I'd challenge _any_ JavaScript physics engine to cope with 50,000 bodies!

Aside from that being a huge amount of parts (so expect it to be slow), is the only issue when you initially add them? Does it run fine afterwards? Are you using polydecomp?

alright I think I just took a wrong approach to my game. I did not think that one body made of 50000 sub-bodies would hit the performance, but now that I think about it it's completely stupid.. I'm going to rethink my logic and try to picture my static floor as one polygon

Alright. I tried creating one object from vectors for the ground. But as I'm doing a 2D tile based game, I'd need to have holes inside the ground such as caverns. After trying tons of orders for my vectors, I finally found something that, when I render does what I want, however, collisions son't work with this object.

I'm creating my object using :

const obj = Bodies.fromVertices(0, 0, [[
  { x: 0, y: 0 }, { x: 0, y: 400 },
  { x: 0, y: 400 }, { x: 400, y: 400 },
  { x: 400, y: 400 }, { x: 400, y: 0 },
  { x: 400, y: 0 }, { x: 0, y: 0 },
  { x: 0, y: 0 }, { x: 100, y: 100 },

  { x: 100, y: 100 }, { x: 300, y: 100 },
  { x: 300, y: 100 }, { x: 300, y: 300 },
  { x: 300, y: 300 }, { x: 100, y: 300 },
  { x: 100, y: 300 }, { x: 100, y: 100 },
  { x: 100, y: 100 }, { x: 0, y: 0 },

]], {
  isStatic: true,
});

It does create a square hole inside of a square but if I add a circle inside the hole it will just go through.. And if I drop this big block on a ground it does not collide either...

Any idea @liabru ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

christianmalek picture christianmalek  路  4Comments

cain picture cain  路  4Comments

maximilianberndt picture maximilianberndt  路  4Comments

253153 picture 253153  路  3Comments

djipco picture djipco  路  4Comments