Skip to content

isStatic causes Infinite Body values #4

@Qriva

Description

@Qriva

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);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions