Jump to content

Collision with the same sprite


Recommended Posts

Hi all, I have a problem with collision.

All my game is based on these codes:

game.physics.arcade.collide(bullets, chest2,collision_handler);

And it works. But... how to code collision two identical bullets? When I write like this:

game.physics.arcade.collide(ebullets, ebullets, collision_handler);

Only one of them is dying. How to do it?

function collision_handler (object1, object2) {


Link to comment
Share on other sites

Hi here is an example of how you can let bullets collide with each other and get killed by using the Phaser.Weapon plugin:

Notice that if your fire two bullets exactly horizontally, they will collide and both get killed.

You could probably extend it to other players(your enemy) as well, since the collision check is done for the entire weapon.bullets group. Hope this helps!

Link to comment
Share on other sites

In your bullet collide function you use ebullets against ebullets collision check. In the first one you are checking bullets against chest2. Is ebullets a group? You need to check a group vs group, so bullets,bullets. otherwise you make sure that you are checking collision for different objects(ebullets vs ebullets will fail if there is only one object with that name). So:

group vs group or sprite vs group or sprite vs sprite

game.physics.arcade.collide(bullets, bullets, collision_handler);


Link to comment
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.

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.


  • Recently Browsing   0 members

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