WiLD11 Posted August 21, 2016 Share Posted August 21, 2016 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 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. 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 More sharing options...
symof Posted August 21, 2016 Share Posted August 21, 2016 Use overlap instead of collision. Collision is intended as a transfer of physics, overlap just checks if they share the same space. WiLD11 1 Link to comment Share on other sites More sharing options...
samme Posted August 21, 2016 Share Posted August 21, 2016 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); WiLD11 1 Link to comment Share on other sites More sharing options...
WiLD11 Posted August 21, 2016 Author Share Posted August 21, 2016 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 I understand now. Thanks for your time Link to comment Share on other sites More sharing options...
Recommended Posts