Matter dynamic collision error

Hello forum, I’m having this issue with matter, I’m trying to activate and deactivate collision between 2 bodies, but something weird is happening, here is a video.

https://www.youtube.com/watch?v=SJPSKnvPXr4

Phaser Version: 3.18.1

Here is the code, is this the expected result? How can I achieve dynamic collisions or what is the right way to do this?

	var config = {
		type: Phaser.AUTO,
		width: window.innerWidth,
		height: window.innerHeight,
		backgroundColor: 0xffffff,
		physics: {
			default: "matter",
			matter: {
				debug: true
			}
		},
		pixelArt: true,
		roundPixels: false,
		antialias: false,
		scene: {
			create: create
		},
		scale: {
			zoom: 4
		}
	};

	var game = new Phaser.Game(config);
	var platform;
	var ball;

	function create() {
		var self = this;
		platform = this.matter.add.rectangle(100, 46, 40, 10, {
			isStatic: true,
			isSensor: true
		});

		ball = this.matter.add.circle(100, 8, 6, {
			isStatic: true
		});

		this.input.on("pointerdown", function() {
			self.matter.body.setStatic(ball, false);
			platform.isSensor = false;
		});
	}

Thanks in advance!

It may help to assign a new collision category when the pointerdown function is called. Something like:

cat1= this.matter.world.nextCategory();
cat2= this.matter.world.nextCategory();

platform = this.matter.add.rectangle(100, 46, 40, 10, {
		isStatic: true,
	});

ball = this.matter.add.circle(100, 8, 6, {
		isStatic: true
	});

platform.setCollisionCategory(cat1);
ball.setCollisionCategory(cat2);
ball.setCollidesWith(cat2);

this.input.on("pointerdown", function() {
		ball.setStatic(false);
		platform.setCollisionCategory(cat2);
      });

@Cannabijoy works like a charm, thanks!

1 Like