Pau 1 Report post Posted March 29, 2018 Hello! I am trying to make a player to collide with the ground. But the ground has been imported from a tilemap using the tiled program. The collision is not working This is the important part of my code: collisionLayer = map.createStaticLayer('collisionLayer', tileset); var players = findObjectsByType('player', map, 'objectsLayer'); player = this.physics.add.sprite(players[0].x, players[0].y, 'dude'); this.physics.add.collider(player, collisionLayer); findObjectsByType is not a phaser native method, but it is working. The code runs without errors, but the collision is not working. I have attached the code. Thanks! example.zip Quote Share this post Link to post Share on other sites
PixelPicoSean 71 Report post Posted March 30, 2018 // your collision tile id is 3 collisionLayer.setCollisionBetween(3, 3); // or use setCollision method collisionLayer.setCollision([3], true); // the same methods can also be called from tilemap instance Quote Share this post Link to post Share on other sites
nhpb 0 Report post Posted June 14, 2018 How did you determine that his collision tile id is 3? I'm having a similar problem - no matter what I've tried I can't get my player to collide with the layer: var map = this.make.tilemap({ key: 'map' }); var collisionTiles = map.addTilesetImage("collisions"); var groundTiles = map.addTilesetImage("tileset"); var collisionLayer = map.createStaticLayer('Collisions Layer', collisionTiles); var layer = map.createStaticLayer('Tile Layer', groundTiles); var layer2 = map.createStaticLayer('Tile Layer 2', groundTiles); collisionLayer.setCollisionBetween(1, 1); player = this.physics.add.sprite(460, 380, 'hero'); player.setCollideWorldBounds(true); this.physics.add.collider(player, collisionLayer); My map file is here: https://github.com/bhamlin3/bow-hunter/blob/master/public/assets/maps/map.json Quote Share this post Link to post Share on other sites