Skip to content

Ignore gravity is not working for matter physics #6473

@peer2p

Description

@peer2p

Version

  • Phaser Version: 3.60.0
  • Operating system: MacOS Ventura 13.3
  • Browser: Chrome 112.0.5615.49

Description

The boolean property ignoreGravity on matter MatterJS.BodyType is not working anymore since release 3.60.0.
Although it is set to true, the body is affected by gravity.

Example Test Code

export class Bullet extends Phaser.Physics.Matter.Sprite {
constructor(...) {
super(...);
...
this.setIgnoreGravity(true);
...
}
}

Additional Information

The evaluation of the flag is missing in method Engine._bodiesApplyGravity.
This should be the correct code for this method, as it was before.
Also without typos in the jsdoc :)

/**
 * Applies a mass dependent force to all given bodies.
 * @method _bodiesApplyGravity
 * @private
 * @param {body[]} bodies
 * @param {vector} gravity
 */
Engine._bodiesApplyGravity = function(bodies, gravity) {
    var gravityScale = typeof gravity.scale !== 'undefined' ? gravity.scale : 0.001,
        bodiesLength = bodies.length;

    if ((gravity.x === 0 && gravity.y === 0) || gravityScale === 0) {
        return;
    }

    for (var i = 0; i < bodiesLength; i++) {
        var body = bodies[i];

        if (body.ignoreGravity || body.isStatic || body.isSleeping){
            continue;
        }
        
        // add the resultant force of gravity
        body.force.y += body.mass * gravity.y * gravityScale;
        body.force.x += body.mass * gravity.x * gravityScale;
    }
};

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions