Jump to content

Matter.js Collider for Follower


Recommended Posts

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


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

    targets: fireSprite,
    z: 1,
    ease: 'Sine.easeInOut',
    duration: 20000,
    yoyo: true,
   repeat: -1

and then I move them around like:

graphics.lineStyle(2, 0xffffff, 1);

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

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:


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


  • Recently Browsing   0 members

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