Matter.js how do you do a system of overlap?

hi,
I made a minimal snippet to show what i want. If the enemy(red) touch the player(green) the player don’t collide with the enemy and the enemy fall to the bounds of the game.
my problem is that the enemy fall outside the game…why ?

https://jsfiddle.net/espace3d/j4qv1f0c/28/

var cat1;
var cat2;
var cat0;
var player;
var enemy;

config = {
	type: Phaser.CANVAS,
	width: 400,
	height: 400,
	backgroundColor: '#0d1018',
	physics: {
		default: 'matter',
		matter: {
			debug: true,
			gravity: {
                y: 1
      },
    }
	},
	callbacks: {
		postBoot: function (game) {
			//game.canvas.style.width = '100%';
			//game.canvas.style.height = '100%';
		}
	},
	scene: {
		preload: preload,
		create: create,
    update: update,
	}
};

var game = new Phaser.Game(config);

function preload() {
	this.load.image("player", "https://i.postimg.cc/KvY7DVGx/player.png");
	this.load.image("enemy", "https://i.postimg.cc/qRk6Mhg4/enemy.png");
}

function create() {
	cat0 = this.matter.world.nextCategory();
	cat1 = this.matter.world.nextCategory();
	cat2 = this.matter.world.nextCategory();
	this.matter.world.setBounds()
	// player is green
	player = this.matter.add.image(200, 300, 'player');
	//enemy is red
	enemy = this.matter.add.image(200, 100, 'enemy');

	//collision category
	enemy.setCollisionCategory(cat1);
  player.setCollisionCategory(cat2);
	enemy.setCollidesWith([cat2]);
  
  this.matter.world.on('collisionstart', function (event) {
  	if (event.pairs[0].bodyB.gameObject.texture.key == "enemy") {
			if (event.pairs[0].bodyA.gameObject.texture.key == "player") {
				console.log('player is hit')
				event.pairs[0].bodyA.gameObject.alpha =.1
        //HERE MY PROBLEM i want that the player collide with nothing so the enemy normaly pass trough but can't go outside the screen and that 's the problem'
        event.pairs[0].bodyA.gameObject.setCollidesWith([cat0])
			}
   }		
	})
}

function update() {
}

thanks.

find by myself…the forum is not what it was :disappointed:
https://jsfiddle.net/espace3d/e7xdtv4m/21/

Hi.
did you got the solution? @espace

Yes thanks, it’s in my jsfiddle above.

Actually i am searching for the solution.

in my project i created two collision groups .but at first time when it collides it is bouncing back ,but i want it to go through it.

do you have any suggestions to achieve it?

Thank you @espace

hi,

You must use setCollisionCategory as like my jsfiddle.

You specify wich object collide.
it’s the same than this example :
https://labs.phaser.io/view.html?src=src\physics\matterjs\collision%20filter.js

i hope it help you.

Actually i did it in another way .
it is working now.

Thank you @espace.

How did you solve this? I am trying to make a quicksand effect when a block passes through an object that cannot be collided with. I would love to know how you got the enemy to hit while not colliding with the player.

case 1: if you want your objects to pass through them and you dont want collision callback
->create a collision group
ex: this.group2 = this.matter.world.nextGroup(true);//gameObjects in this group wont collide with
each other
this.obj.setCollisionGroup(this.group2)

case 2: If you want your objects to pass through them and you want collision callback
->create a sensor for the object
var trigger = this.matter.add.image(250, 450, ‘image’).setStatic(true).setSensor(true)

i hope this helps @Kptkrunch