s4m_ur4i

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

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 :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.