s4m_ur4i Posted March 24, 2018 Share Posted March 24, 2018 Hey there, I am still struggling a lot with Phaser3 due to the documentation is still in work. I made two simple sprites, that collide, what I experience is that >body.blocked.down< nor the other properties (left, right, top) ever change. They are always: false. No matter if a collision happens or not. A bit of code: //These are the arcade configs: physics: { default: 'arcade', arcade: { gravity: {x: 0, y: 2000}, debug: true, overlapBias: 20 } } //TileA this.plat = this.physics.add.sprite(400, 1100, 'platform'); this.plat.displayWidth = 500; this.plat.body.allowGravity = false; this.plat.body.immovable = true; //TileB is a custom class which just extends this.physics.add.sprite this.minion = new tileB(this, 500, 200); //collision works well with: this.physics.world.collide(this.plat, this.minion); However, the body.blocked property is logged in my update of the custom (tileB) class - and it is always false. No matter if it's colliding. Here is the code of the tileB class: class tileB extends Phaser.Physics.Arcade.Sprite { constructor(config) { super(config.scene, config.x, config.y, 'minion'); this.scene.physics.world.enable(this); this.scene.add.existing(this); this.scene.layers.minions.add(this); this.controls = this.scene.input.keyboard.createCursorKeys(); //write controls class this.alive = true; this.body.maxVelocity.y = 1500; this.body.setSize(50, 100, false); this.body.setOffset(80, 60); this.scene.events.on('update', this.update, this); } update() { if(this.data.active) { console.log(this.body.blocked.down) if (this.controls.left.isDown) { this.setVelocityX(-200); this.anims.play('left', true); } else if (this.controls.right.isDown) { this.setVelocityX(200); this.anims.play('right', true); } else { this.setVelocityX(0); this.anims.play('turn'); } if (this.controls.up.isDown && this.body.blocked.down) { this.setVelocityY(-200); } } } } I have looked into the super mario example by @nkholski as he used body.blocked.down too. I had a hard time to find the point I am missing. Would be glad if someone helped me out nkholski's platformer boilerplate: Thanks in advance Link to comment Share on other sites More sharing options...
samme Posted March 24, 2018 Share Posted March 24, 2018 The tile update method may be running too early or too late. Link to comment Share on other sites More sharing options...
PixelPicoSean Posted March 25, 2018 Share Posted March 25, 2018 Currently `blocked` only shows whether a body is collide with world bounds, I don't know whether that is a bug or by design. For your purpose, check `touching.down` instead. Link to comment Share on other sites More sharing options...
samme Posted March 25, 2018 Share Posted March 25, 2018 body.blocked is for tiles and world bounds, body.touching is for other sprites. Same as Phaser 2. s4m_ur4i 1 Link to comment Share on other sites More sharing options...
s4m_ur4i Posted March 25, 2018 Author Share Posted March 25, 2018 @samme thanks for clarifying this helped me. Link to comment Share on other sites More sharing options...
Recommended Posts