Can't add collision between layer and player

Hello, have problem written above. Tried to find solutions and failed to do so.

Here’s my code regarding tilemap and character:

function preload() {
    this.load.image('dungeonTiles', 'assets/tileset.png');
    this.load.tilemapTiledJSON('map', 'assets/map.json');
    this.load.spritesheet('player', 'assets/player_spritesheet.png', {
        frameWidth: 50,
        frameHeight: 37
    });
}

function create() {
    gameState.map = this.add.tilemap('map');
    gameState.dungeonTileset = gameState.map.addTilesetImage('dungeon', 'dungeonTiles');

    gameState.backgroundLayer = gameState.map.createStaticLayer('Background', gameState.dungeonTileset);
    gameState.mapLayer = gameState.map.createStaticLayer('Map', gameState.dungeonTileset);
    gameState.miscLayer = gameState.map.createStaticLayer('Misc', gameState.dungeonTileset);

    gameState.mapLayer.setCollisionByExclusion([-1]);

    this.physics.world.bounds.width = gameState.mapLayer.width;
    this.physics.world.bounds.height = gameState.mapLayer.height;

    gameState.player = this.physics.add.sprite(73, 398, 'player', 0);
    gameState.player.setCollideWorldBounds(true);

    this.physics.add.collider(gameState.mapLayer, gameState.player);
}

const config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    backgroundColor: "#f",
    physics: {
        default: 'arcade',
        arcade: {
            gravity: { y: gameState.gravity },
            debug: true
        }
    },
    scene: {
        preload,
        create,
        update
    }
};

Thanks in advance!!!

Hi,
Your snippet is very long. The best is just post the minimal snippet of your problem. And the top is make a jsfiddle with this snippet like this : https://jsfiddle.net/espace3d/vLq08gke/12/

So the others may help you :wink:

Often when you do this exercice you identify yourself the problem!

Yeah, sorry about that, changed.

Your collider must be in the update function.

I read that phaser 3 collider checks collisions automatically after being initiated in create, no? Did it change again?

Yes i made a mistake. If i have time further i will see about your problem.

Have you see this example, maybe it could help you…
https://labs.phaser.io/edit.html?src=src/game%20objects\tilemap\collision\tiled%20map%20and%20impact.js

Sorry it’s with impact js
try this : https://labs.phaser.io/edit.html?src=src/bugs\ap%20tilemap.js

Hi @tukanoidd,
Your code seems correct for me. Maybe the problem is in the “map.json” file.
You could try to log one tile and check its index and collide properties. Check if tile index is allways -1.

Regards.

P.S.: Just one observation, you can use the keyboard.addKeys () method in the create () function only once.

Tried it, but the problem is that because I have 3 layers, Tiled exports 3 different csv files, and when i tried to import all 3 of them and create layers out of them, only the last one of them was visible for some reason

Hey, thanks, but what exactly could be wrong with json file? What in your opinion can affect layer not to be collidable?