Jump to content

Matter.js Collider for Follower


Gabe1515
 Share

Recommended Posts

Hello, I am using a group of pathed followers similar to this example:

https://www.phaser.io/examples/v3/view/paths/zig-zag-path

But I need them to have colliders so they can interact with and damage the player collider. I am using the matter physics like so in my config:

 physics: {
        default: 'matter',
        matter: {
            gravity: { x: 0, y: 1 },
            debug: true
        },

and with a followers group:

followers = this.add.group(); 

and then in update if certain conditions are met I spawn a new one on the path like so:

var fireSprite = followers.create(0, -50, 'firesprite');
fireSprite.setData('vector', new Phaser.Math.Vector2());
fireSprite.setData('label', 'firesprite');


this.tweens.add({
    targets: fireSprite,
    z: 1,
    ease: 'Sine.easeInOut',
    duration: 20000,
    yoyo: true,
   repeat: -1
});

and then I move them around like:

graphics.clear();
graphics.lineStyle(2, 0xffffff, 1);
path.draw(graphics);

var fireSprites = followers.getChildren();
for (var i = 0; i < fireSprites.length; i++) {
    var t = fireSprites[i].z;
    var vec = fireSprites[i].getData('vector');
    path.getPoint(t, vec);
    fireSprites[i].setPosition(vec.x, vec.y);
    fireSprites[i].setDepth(fireSprites[i].y);
}

and that all works fine and spawns the fireSprite followers and moves them around, but I want them to have a collider. Things like these:

this.physics.matter.world.enable(fireSprite);
this.matter.add(fireSprite);
fireSprite.body.setCircle(1);

don't work and throw errors. Do I need to create the sprites with matter physics somehow? does the 'followers' group need to be made with matter physics?

thanks for any help

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...