Jump to content

Arcade.Body : body.blocked (any) is always false


s4m_ur4i
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...