# Matter dynamic collision error

**URL:** <https://phaser.discourse.group/t/matter-dynamic-collision-error/2858>\
**Category:** Phaser 3\
**Created:** [June 22, 2019, 4:49am UTC](https://phaser.discourse.group/t/matter-dynamic-collision-error/2858 "2019-06-22T04:49:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cruzlutor](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/cruzlutor/32/475_2.png) [@cruzlutor](https://phaser.discourse.group/u/cruzlutor)\
**Post date:** [June 22, 2019, 4:49am UTC](https://phaser.discourse.group/t/matter-dynamic-collision-error/2858/1 "2019-06-22T04:49:33Z")

</div>

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](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!

---

<div class="post-metadata">

**Author:** ![Cannabijoy](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/cannabijoy/32/1511_2.png) [@Cannabijoy](https://phaser.discourse.group/u/Cannabijoy)\
**Post date:** [June 22, 2019, 5:42am UTC](https://phaser.discourse.group/t/matter-dynamic-collision-error/2858/2 "2019-06-22T05:42:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cruzlutor](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/cruzlutor/32/475_2.png) [@cruzlutor](https://phaser.discourse.group/u/cruzlutor)\
**Post date:** [June 22, 2019, 4:09pm UTC](https://phaser.discourse.group/t/matter-dynamic-collision-error/2858/3 "2019-06-22T16:09:16Z")

</div>

@Cannabijoy works like a charm, thanks!
