I'm trying to have my bullets group that already collides with the enemies, both of them are a group, but now that I want to add a static block or obstacle, it simply wont collide or overlap or nothing, what I want is that when the bullet collides or overlaps it gets destroyed or at least bounce into the obstacle, see code below:
////////////////My Bullets//////////These work fine and collide correctly with my enemies.//////
createBullets: function() {
this.bullets = this.game.add.group();
this.bullets.enableBody = true;
this.bullets.physicsBodyType = Phaser.Physics.P2JS;
this.bullets.createMultiple(100, 'bulletSprite', 0, false);
this.bullets.setAll('anchor.x', 0.5);
this.bullets.setAll('anchor.y', 0.5);
this.bullets.setAll('outOfBoundsKill', true);
this.bullets.setAll('checkWorldBounds', true);
},
fireBullet: function(){
if (this.bulletTimer < this.game.time.time) {
this.bulletTimer = this.game.time.time + 500;
this.bullet = this.bullets.getFirstExists(false);
if (this.bullet) {
this.bullet.reset(this.tanke.x, this.tanke.y - 20);
this.bullet.body.setCollisionGroup(this.bulletCG);
this.bullet.body.collides([this.figuraCG]);
this.bullet.body.velocity.y = -3500;
}
}
},
//////This is the block or obstacle this just wont work no matter what I try///////////
makeOneBloque: function(){
this.bloque = this.game.add.sprite(500, 950, 'Blokes');
this.bloque.enableBody = true;
this.game.physics.p2.enable(this.bloque, true);
this.bloque.body.kinematic = true;
this.bloque.body.collides(this.bullets, this.collisionBulletBloque, this); //////I tried overlaps and it just crashes the lvl
},
collisionBulletBloque: function(bullet) {
bullet.sprite.destroy();
},
Any Help would be greatly appreciated.