So I'm trying to make a simple maze in Phaser.js, but collision has been a pain. I have gotten to the point where I can detect collisions between the sprite and my wall, but the sprite passes right through, even though I set the wall as immovable. Pretty new to phaser and js as a whole so it's probably something simple lol
create() {
this.cursors = this.input.keyboard.createCursorKeys()
this.wall50x100 = this.physics.add.image(300,200,'50x100').setImmovable()
this.sprite = this.physics.add.sprite(200,200,'sprite')
this.sprite.setOrigin(0,0)
//////////////////////////////////////////
this.wall1 = this.physics.add.image(500,200,'50x100').setImmovable()
this.wall1.setOrigin(0,0)
//////////////////////////////////////////
this.back = this.add.image(50,500,'back')
this.back.setOrigin(0,0)
this.back.setInteractive()
this.back.on('pointerup',function(){
this.scene.start('Scene2');
},this)
this.add.text(20, 20, "Scene: 3", {font: "25px Arial", fill: "green"});
this.physics.add.collider(this.sprite, this.wall50x100, function(sprite, wall50x100){
console.log('Collision Detected')
}.bind(this))
}
I was expecting the sprite to not pass through the wall, but it did.
There are atleast two posibile reasons I can think of, why the collision might not work:
positionyou override the phaser - "physics".But it could be many other thing, these where the top two I could think of without seeing more code.