Jump to content

Arcade Collision Problem


WiLD11
 Share

Recommended Posts

Hello! 

There is this really weird problem that I can't seem to fix.

So the problem is when my player's body collides with a particle body, it does some really weird stuff

26ecc57e160672dd1a757123e762373f.png

 

Here is how I'm checking collision:

    game.physics.arcade.collide(coin.coin, player.coinCol, function(player, coin) {
        pizza.coins += 1;
        coin.destroy();
    }, null, this);

The coins are part of a particle emitter, which gets set off in above the player

  this.coin = game.add.emitter(totem.x, 100, 0);


    this.coin.makeParticles('particle');
    this.coin.setAll('anchor.x', 0.5);
    this.coin.setAll('anchor.y', 0.5);

    this.coin.gravity = 500;
    this.coin.width = 30;
    this.coin.height = 10;

    game.physics.arcade.enable(this.coin);

 

When the coin falls, and the player's body touches it, it works like it should. But when it touches the world boundaries at the same time, it somehow doesn't work. 

The player is made up of two bodies, one is the totem collision box, which is set at the top of the player, and one that is the coin collision box which covers the whole player.

debug.png

Here is how I'm setting up the coin collision box 

    this.coinCol = game.add.sprite(game.world.centerX, game.height);
    this.coinCol.scale.setTo(5, 6);
    this.coinCol.anchor.setTo(0.5, 0.5);
    game.physics.arcade.enable(this.coinCol);


update...

    this.coinCol.x = this.player.x + 100;
    this.coinCol.y = this.player.y-this.player.height/2;

If there is only 1 coin in the scene and it touches the boundaries, it works as expected.

 

I have some ideas about how this might have happened, but I want to hear what other have got to say.

 

Thanks!

Link to comment
Share on other sites

Also:

You don't need to enable physics on emitters; the particles already have physics bodies. :)

I can't tell if coin.coin is a Sprite or an Emitter, but you can test overlaps on the emitter itself. It will loop through all the particles:

game.physics.arcade.overlap(player.coinCol, coinEmitter, function(coinCol, coinParticle) {
    // …
}, null, this);

 

Link to comment
Share on other sites

2 hours ago, samme said:

Also:

You don't need to enable physics on emitters; the particles already have physics bodies. :)

I can't tell if coin.coin is a Sprite or an Emitter, but you can test overlaps on the emitter itself. It will loop through all the particles:


game.physics.arcade.overlap(player.coinCol, coinEmitter, function(coinCol, coinParticle) {
    // …
}, null, this);

 

 

Oh! Thanks! It works as expected now :D I understand now. Thanks for your time :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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