Jump to content

Collision between a group of bullets and enemy


yarik2803
 Share

Recommended Posts

Hi! I've been working with Phaser for a few days and I faced an issue which I can't solve. I'm making a simple game which has two heroes/enemies(sprites) who can shoot bullets. For that case I decided to make a group of bullets. But the collision between the group and one of the heroes doesn't work. I tried this:

// hero2 - the sprite, bullets - the bullet group
this.game.physics.arcade.collide(hero2, bullets, this.collision, null, this);

// Here is the function collision
function collision(hero2, bullets){
   hero2.kill();
}      

I've been searching how to solve that problem for quite a long time but I couldn't find any examples of collision between a bullet group and a sprite. I would be very grateful if somebody could help me :)

Link to comment
Share on other sites

Hey yarik,

You may want to make sure that both hero2 and the bullets group are both enabled in the arcade physics system. You do that in the create function like so:

this.game.physics.arcade.enable(hero2); 
 
this.bullets.enableBody = true;

Also make sure that the this.game.physics.arcade.collide call is in the update function.

Let us know if that works!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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