p5-matter-examples icon indicating copy to clipboard operation
p5-matter-examples copied to clipboard

Magnet class doesn't behave like a magnet

Open stephanbogner opened this issue 2 years ago • 1 comments

We (@b-g and me) used the magnet class in the "attractor duo" example and noticed that it might not behave like an actual magnet 😆

I think in reality once an element comes closer to one magnet, it would snap towards that magnet, because pull force is not linear to distance.

Apparently the pull force of a magnet follows the "inverse square law".

Maybe you know more @ByronStar

stephanbogner avatar Jul 25 '22 14:07 stephanbogner

I have added Newton's Law of Gravity to the Magnet class as defined in https://github.com/liabru/matter-attractors/blob/master/build/matter-attractors.js libaru's MatterAttractor plugin. The attractor duo example is changed accordingly. The static bodies need mass defined - otherwise ist is Infinite. Please have a look @stephanbogner and comment if this is not the desired result.

ByronStar avatar Jul 25 '22 16:07 ByronStar

@ByronStar Thanks for fixing this 👍 I renamed the example back to magnet and magnet-duo and reexported the docs

The static bodies need mass defined - otherwise ist is Infinite. That is good to know too!

stephanbogner avatar Sep 13 '22 07:09 stephanbogner