# Unwanted collisions between players when loading tilemap

**URL:** <https://phaser.discourse.group/t/unwanted-collisions-between-players-when-loading-tilemap/8300>\
**Category:** Phaser 3\
**Created:** [December 7, 2020, 11:08am UTC](https://phaser.discourse.group/t/unwanted-collisions-between-players-when-loading-tilemap/8300 "2020-12-07T11:08:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![damaca](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/damaca/32/4442_2.png) [@damaca](https://phaser.discourse.group/u/damaca)\
**Post date:** [December 7, 2020, 11:08am UTC](https://phaser.discourse.group/t/unwanted-collisions-between-players-when-loading-tilemap/8300/1 "2020-12-07T11:08:02Z")

</div>

Hello, thanks for taking the time to read this. I’m working on my first game in Phaser. I created a couple of players and a scene where both players will fight some enemies. I created a physics group for the players and a static layer for my tileset. But when I add the collider between the players and the ground layer, it also adds a collider between the players, and I don’t want that. Any suggestions?

this.players = this.physics.add.group();

this.player0 = new Player(this, 128, 32);  
this.player1 = new Player(this, 64, 32);

this.players.add(this.player0);  
this.players.add(this.player1);

this.map = this.make.tilemap({ key: ‘map1’ });  
this.groundTiles = this.map.addTilesetImage(‘Tile\_sheet’, ‘tileSheet’);  
this.groundLayer = this.map.createStaticLayer(‘Ground’, this.groundTiles, 0, 0);

this.groundLayer.setCollisionBetween(1, 29);

this.physics.add.collider(this.players, this.groundLayer);

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [December 7, 2020, 5:02pm UTC](https://phaser.discourse.group/t/unwanted-collisions-between-players-when-loading-tilemap/8300/2 "2020-12-07T17:02:46Z")

</div>

You mean the players are colliding with each other? Are you sure?

---

<div class="post-metadata">

**Author:** ![damaca](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/damaca/32/4442_2.png) [@damaca](https://phaser.discourse.group/u/damaca)\
**Post date:** [December 7, 2020, 9:07pm UTC](https://phaser.discourse.group/t/unwanted-collisions-between-players-when-loading-tilemap/8300/3 "2020-12-07T21:07:40Z")

</div>

100% sure. If player0 runs into player1, player0 slows down and player1 is pushed. And if both of them run in opposite directions they stop.

The players also have a collider with this group of platforms, and deleting this fixes the problem. Am I doing something wrong here??

this.platforms = this.physics.add.staticGroup();  
this.platforms.create(366, 166, ‘platform’);  
this.platforms.create(400, 102, ‘platform’);

this.physics.add.collider(this.players, this.platforms);

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [December 7, 2020, 10:12pm UTC](https://phaser.discourse.group/t/unwanted-collisions-between-players-when-loading-tilemap/8300/4 "2020-12-07T22:12:15Z")

</div>

It looks correct.

What happens if you remove the `groundLayer` collider?

---

<div class="post-metadata">

**Author:** ![damaca](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/damaca/32/4442_2.png) [@damaca](https://phaser.discourse.group/u/damaca)\
**Post date:** [December 8, 2020, 1:37pm UTC](https://phaser.discourse.group/t/unwanted-collisions-between-players-when-loading-tilemap/8300/5 "2020-12-08T13:37:13Z")

</div>

I just fixed it! When I copied the code I didn’t include a few things because I thought it wasn’t relevant, but it was. Basically when I did this:

this.physics.add.collider(this.players, this.platforms);

Platforms was undefined, so it added a collider between the players. Makes so much sense… Thanks for your time though!
