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

isStatic causes Infinite Body values #4

Open
Qriva opened this issue Aug 15, 2017 · 1 comment
Open

isStatic causes Infinite Body values #4

Qriva opened this issue Aug 15, 2017 · 1 comment

Comments

@Qriva
Copy link

Qriva commented Aug 15, 2017

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);
    }
}
@tandryukha
Copy link

I faced same bug. It would be great to have it fixed.

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

No branches or pull requests

2 participants