Make two bodies NOT collisionable with each other

Hi all

I am working with Matter in this. is there a way to make two “matter enabled” sprites not collide with each other?

What I want to achieve is to have one sprite on top of the other at ALL TIMES.

Thanks!

Add them to the same collisionFilter: group

let group = this.matter.world.nextGroup(true)

let body = this.matter.add.image(x, y, 'image')
    body.setBody(
      {
        type: 'rectangle',
        width: width,
        height: height
      },
      {
        collisionFilter: {
          group: group
        },
      }

I’m not sure if you can use a phaser container in this case to stick both sprites together. Try it.

1 Like

Makes sense now that you mention it.
I gave it a go but when the game starts both sprites start going up and stays like that, colliding with the world’s upper bound.
What did work is that both sprites are one on top of the other.

Strange. Do you use other physical bodies in this game? Does the see background has a physical body?

Maybe you want to post a bit more of your code?

The only other collisionable is the tilemap, but not all of it, just the land tiles. It’s made collisionable with the setCollisionByProperty.
Maybe I should open TILED, and make the water tile FALSE to collision (currently it does not have the property, I only created the property in Tiled for the land tiles).

So yannick, I managed to figure out the strange behaviour shown in the GIF (stupid begginer code mistake hehe).
Now I have this group, with the two non collisionable bodies in it. What I see now is that the friction the boat had when moving is gone. I need the friction back so I can have a controlled movement of the ship. Do I have to set the friction to the group?

I do not know if you can add a friction to the group. I have always added a friction to all bodies in a group individually.

Take a look at two classes I built with matter. Hope it helps.