chon27 Posted September 5, 2018 Share Posted September 5, 2018 Hello! I'm problems with this case; I have a map loaded from tiled with blocks that they are collisionable, some like: // Import tiled map this.map = this.make.tilemap({ key: 'fase' }); this.tileset = this.map.addTilesetImage('tileset'); this.layer = this.map.createDynamicLayer(0, this.tileset, 0, 0); // Set collision in two type of blocks this.layer.setCollisionBetween(0, 2); // Set collision between player and layer this.physics.add.collider(this.solomon, this.layer); So this part is correctly functional as can see in the gif, player walk over blocks. Quote this.solomon is created with a new class that extends from Phaser.Physics.Arcade.Sprite. Then I created a new movable block like this: this.movil = this.physics.add.sprite(180, 104, 'block'); this.movil.setVelocityX(30); this.movil.setImmovable(true); this.movil.body.allowGravity = false; this.movil.setBounce(1); // Collision with the layer this.physics.add.collider(this.movil, this.layer); // And collision with the player this.physics.add.collider(this.solomon, this.movil); My problem is why the player doesn't collision with the layer when he is on the movable block. However if I walk against it while I'm on movable block, the collision does work!! (As seen at the end of gif, before he falls) Some help? Link to comment Share on other sites More sharing options...
samme Posted September 5, 2018 Share Posted September 5, 2018 Try // And collision with the player this.physics.add.collider(this.solomon, this.movil, function (solomon) { var velocity = solomon.body.velocity; if (velocity.x === 0) velocity.x = 0.001; }); chon27 1 Link to comment Share on other sites More sharing options...
chon27 Posted September 11, 2018 Author Share Posted September 11, 2018 Thanks for you reply. I was on vacation and I couldn't try it until now. This does not work but you give me an idea of problem that I solved like this: this.physics.add.collider(this.solomon, this.movil, function() { this.onPlatform = true; }); And the other side, at update function: if(this.onPlatform && this.solomon.body.velocity.x === 0) { // In order to know direction on movement (1 to right or -1 to left) let dir = this.movil.body.newVelocity.x > 0? 1: -1; // Then sets velocity X to solomon multiplicate by the direction to make collision by both sides this.solomon.body.setVelocityX(0.001*dir); } // Reset onPlatform to set false when leaves it this.onPlatform = false; Now I have only to optimize or atomize a bit. The result in the gif. Thank you very much! blackhawx and samme 2 Link to comment Share on other sites More sharing options...
Recommended Posts