yarik2803

Collision between a group of bullets and enemy

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

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.