Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matter.js Gravity Point

Tags:

matter.js

Is it possible to create a single gravity / force point in matter.js that is at the center of x/y coordinates?

I have managed to do it with d3.js but wanted to enquire about matter.js as it has the ability to use multiple polyshapes.

http://bl.ocks.org/mbostock/1021841

like image 383
MichaelBell Avatar asked Aug 11 '15 09:08

MichaelBell


1 Answers

Ah, the illustrious answer has arisen.

https://github.com/liabru/matter-js/pull/132

not sure if there is any interest in this. I'm a fan of what you have created. In my latest project, I used matter-js but I needed elements to gravitate to a specific point, rather than into a general direction. That was very easily accomplished. I was wondering if you are interested in that feature as well, it would not break anything.

All one has to do is setting engine.world.gravity.isPoint = true and then the gravity vector is used as point, rather than a direction. One might set:

engine.world.gravity.x = 355;
engine.world.gravity.y = 125;
engine.world.gravity.isPoint = true;

and all objects will gravitate to that point.

If this is not within the scope of this engine, I understand. Either way, thanks for the great work.

like image 183
MichaelBell Avatar answered Sep 21 '22 00:09

MichaelBell