Hi everyone,
I’ve been having a TON of fun with Phaser 3 and getting to know how everything works. I’m building a little RPG for my friends and I to play and I’m using TILED to make the maps.
Since I only want my player to collide with the base of the tree, I’ve added collision boxes in the Tiled Collision Editor and I can confirm that they show up in the tilemap because I see them when I check the ‘Show Tiled Collision Shapes’ box in the view of TILED’s GUI.
It seemed to me that using setCollisionFromCollisionGroup() would be a nice function to set the collisions. setCollisionByExclusion([-1]) works and I assumed this function would work similarly, but use the collision bounding boxes I set in TILED instead of the entire tile.
Can someone help me understand what I’m doing wrong? It seems I either misunderstand what setCollisionFromCollisionGroup() is supposed to do, or how to use it properly. See below for the relevant code in the create function:
var map = this.make.tilemap({ key: 'map' });
var tiles = map.addTilesetImage('Extereior_Nature_Combined', 'tiles');
var tiles_2 = map.addTilesetImage('Trees_2', 'tiles_2');
this.Collisions = map.createLayer('CollisionByExclusionLayer', tiles, 0, 0); //this works
this.Collisions.setCollisionByExclusion([-1]); //this works
//Below this comment I do not get an error, but I do not get any physics interactions
//this.players is a physics group
//the callback was added to see if the collisions were happening and I just didn't see them, but nothing //logs. I'm using arcade physics and all the bounding boxes are rectangles.
this.Object_Collisions = map.createLayer('CollisionByObjectLayer', tiles, 0, 0);
this.Object_Collisions.setCollisionFromCollisionGroup(true);
this.physics.add.collider(this.players, this.Object_Collisions, ()=>console.log('collided'),null,this);
Any help here would be greatly appreciated. Being able to set the bounding boxes for these collisions from tiled would make getting the levels put together so much easier :).