Coder Social home page Coder Social logo

matter-attractors's People

Contributors

liabru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

matter-attractors's Issues

Gravity Doesn't Seem to Increase As Distance Between Objects Decreases

I'm making a game with matter.js where you can create your own solar system, but instead of elliptical orbits like you'd expect where the planets would get close to the star and then swing around it, the planets always keep their orbits completely centered around the star. Is there any way I can fix this?
Note: I have tried to use the built-in Newtonian gravity, but it doesn't work at all with anything I've tried.

For reference:
Elliptical Orbits Wrong

Magnetic attraction

Hello!

I'm attempting to achieve and effect where the attraction between bodies varies depending on their distance and mass (like a magnet). I've attempted to use the following function, using the standard vector math formula, but so far have not been able to replicate the effect:

function(bodyA, bodyB) {
                let vx = bodyB.position.x - bodyA.position.x;
                let vy = bodyB.position.y - bodyA.position.y;
                let m = Math.sqrt(vx * vx + vy * vy);
                let dx = vx / m;
                let dy = vy / m;

                return {
                  x: (dx * (bodyA.mass * bodyB.mass)) / m,
                  y: (dy * (bodyA.mass * bodyB.mass)) / m
                };
}

Probably I don't understand properly which x/y values should be returned. Any assistance would be greatly appreciated! πŸ˜„

Can this be used to even distribute particles inside an area?

I have a spherical area, and I'd like for particles to naturally distribute themselves somewhat evenly inside the area.

Could I possibly use Matter's gravity along with this to somehow make them want to distribute themselves evenly inside the area?

Repulsion Example

I am trying to use this plugin, but maybe Im not understanding how the function is supposed to work.

I trying to apply a repulsion so I am using the plugin like so:

  plugin: {
    attractors: [
      function(bodyA, bodyB) {
        var force = {
          x: -(bodyA.position.x - bodyB.position.x) * 1e-5,
          y: -(bodyA.position.y - bodyB.position.y) * 1e-5,
        };

        // apply force to both bodies
        Matter.Body.applyForce(bodyA, bodyA.position, Matter.Vector.neg(force));
        Matter.Body.applyForce(bodyB, bodyB.position, force);
      }
    ]
  }

but the force seems to be greater when the bodies are further from each other. why is this?

example:
https://codepen.io/adamcoulombe/pen/oNjLBBM

Not working in IE11

The plugin is breaking when running in IE11. You can try it with your example page aswell.

Error is: "Invalid calling object"...

NPM Package broken?

Hi there,

I was playing around with matter and I am very impressed. So first of all, a big thank you for this.

So I tried to use the matter-attractor plugin in a webpack context. Using something like this:

import Matter from 'matter-js';
import MatterAttractor from 'matter-attractors';
Matter.use(MatterAttractor);

But webpack is throwing an error at me:

 ERROR  Failed to compile with 1 errors                                                                                                                                      

This dependency was not found:

* Matter in ./~/matter-attractors/build/matter-attractors.js

To install it, you can run: npm install --save Matter

So thats a little strange, since the Matter dependency is called matter-js. I checked the source and saw that under the build/directory there are some calls to require('Matter'). I decided to not mess around with that and as the index.js is using require('matter-js') my current workaround is something ugly like this:

import Matter from 'matter-js';
Matter.use(require('../../../../node_modules/matter-attractors/index'));

And its working just fine.

Hope you can fix the issue soon.
Thanks in advance. :)

isStatic causes Infinite Body values

Because static bodies have infinite mass and other propeties, after setting at least 1 body to static this results with completely bugged stage (bodies get infinite prop.)

Actually there should be possibility to add gravity force for static bodies - is it required for body to has infinity?
Anyway I think quick fix like this would be nice anyway because everything just stops working at the moment.

gravity: function(bodyA, bodyB) {
    // apply force only if both bodies are not static
    if(!bodyA.isStatic && !bodyB.isStatic){
      // use Newton's law of gravitation
      var bToA = Matter.Vector.sub(bodyB.position, bodyA.position),
        distanceSq = Matter.Vector.magnitudeSquared(bToA) || 0.0001,
        normal = Matter.Vector.normalise(bToA),
        magnitude = -MatterAttractors.Attractors.gravityConstant * (bodyA.mass * bodyB.mass / distanceSq),
        force = Matter.Vector.mult(normal, magnitude);

      // to apply forces to both bodies
      Matter.Body.applyForce(bodyA, bodyA.position, Matter.Vector.neg(force));
      Matter.Body.applyForce(bodyB, bodyB.position, force);
    }
}

Disabling the attractors at will.

Hey so I'm working on creating body orbits which pull certain other bodies towards them.
I've managed to create the code that allows some bodies to only exert forces on certain other bodies but right now my orbits don't work properly as the forces are constantly being applied to the attracted ones even after they reach the desired orbit (range away) around the attractor.

Is there a built-in sleep switch for matter-attractors? If not can you maybe point me in the right direction where I could implement such a feature myself within your project? This would really come in handy as the device that I'm coding this for doesn't have a lot of processing power (it's a table top AR projector) and I want to make the app take up the least amount of CPU time possible.

Thanks!

Wind?

Wondering how you'd simulate wind.
Single attractor pulling all bodies towards it?
Negative attractor gravity pushing all away? (that seems more like a circular 'hill' with even slopes).

I'm interested in Matter and your plugin to simulate a game of golf, so looking to simulate forces like wind, friction and gravity with 2 dimensional slopes etc.

Thanks for any insights and great plugin :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.