Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attractor only works when added before other bodies #6

Open
lonekorean opened this issue Oct 11, 2017 · 4 comments · Fixed by MetarDev/matter-attractors#1
Open

Attractor only works when added before other bodies #6

lonekorean opened this issue Oct 11, 2017 · 4 comments · Fixed by MetarDev/matter-attractors#1

Comments

@lonekorean
Copy link

It seems that an attracting body will not attract other bodies added to the world before it.

Demo here: https://codepen.io/lonekorean/pen/cfc51f387d8f32727288f3a59113ceeb

Comment/uncomment line 42/43 to see.

@jpagand
Copy link

jpagand commented Oct 12, 2017

This PR will fix this issue:
#5

@probityrules
Copy link

I'm running into this issue as well. I realize that the current version is an optimization so that the number of checks doesn't increase quite as quickly as new bodies are added, but it only works under the assumption that all affected bodies for a given attractor all include the self-same attractor. However, once there are bodies that don't include the attractor, but should be affected by another body having said attractor, it seems that either a full loop like @jpagand is suggesting be used, or, maybe slightly more efficient, maintaining a smaller list of attractor-including bodies to be checked against all other bodies.

For example, if I create a body with a "magnet" attractor, requiring all bodies that are affected by this attractor also have a "magnet" attractor probably makes sense. However. if I create a body with a "fan" attractor, having every body that should be blown by a fan also include a "fan" attractor seems to make a little less sense.

Another possibility may be to go through the bodies as currently set up, but rather than reference the attractor functions on each body, let them reside elsewhere and iterate through all of the attractor functions for all bodies (so that their absence on a given body doesn't preclude them from being affected by a body later in the list). Not sure if much is gained going this route; just thinking it through.

@whxru
Copy link

whxru commented Dec 3, 2018

I met the same problem too and it's easy to fix the bug, but it seems that the author will no longer update the plugin so I fix the bug and publish to npm, you can get detail in my repo.

@luigimannoni
Copy link

luigimannoni commented Jul 18, 2019

Package from @whxru fixed my issue and works with the latest matterjs installed (0.14.2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants