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

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 ?

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) {
			// = '100%';
			// = '100%';
	scene: {
		preload: preload,
		create: create,
    update: update,

var game = new Phaser.Game(config);

function preload() {
	this.load.image("player", "");
	this.load.image("enemy", "");

function create() {
	cat0 =;
	cat1 =;
	cat2 =;
	// 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.setCollidesWith([cat2]);'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'

function update() {


find by myself…the forum is not what it was :disappointed:

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


You must use setCollisionCategory as like my jsfiddle.

You specify wich object collide.
it’s the same than this example :\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 =;//gameObjects in this group wont collide with
each other

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

How to overlap tiled layer and sprite? I have a layer of objects and my player sprite, and I want to detect when they overlaping. @ajay can you show me an example?