matterjs attractor plugin not working with image
Version
- Phaser Version: 3.22
- Operating system: Linux
- Browser: Firefox
Description
I cannot make matterjs attractor plugin work with a simple image or sprite. I can see that the example works with imageStack, but not with an image or a sprite. Tried looking at the code, but cannot see what makes imageStack special in this case.
Example Test Code
I modified the example just to have one image from imageStack and one normal image:
function create ()
{
this.matter.world.setBounds();
this.matter.add.image(0, 400, 'alien', null, {
mass: 0.5,
ignorePointer: true
});
this.matter.add.imageStack('alien', null, 0, 500, 1, 1, 0, 0, {
mass: 0.5,
ignorePointer: true
});
var sun = this.matter.add.image(400, 200, 'sun', null, {
shape: {
type: 'circle',
radius: 64
},
plugin: {
attractors: [
function (bodyA, bodyB) {
return {
x: (bodyA.position.x - bodyB.position.x) * 0.000001,
y: (bodyA.position.y - bodyB.position.y) * 0.000001
};
}
]
}
});
this.matter.add.mouseSpring();
}
This makes only the alien from imageStack get attracted to the sun.
I'm experiencing the exact same issue.
Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.
The plugin had a bug which meant it failed to attract bodies that came before it in the World list. I fixed it to work on any body.