finspin Posted August 1, 2015 Share Posted August 1, 2015 Hi, my first game and first post on this forum. I'm looking for help with collisions, having difficult time to understand why they don't work as expected. There are 3 bouncing balls but sometimes they collide "too early", meaning they bounce off each other before they actually touch. In some cases they collide as expected. Could you show me what I'm doing wrong here?var game = new Phaser.Game(480, 640, Phaser.AUTO, '', { preload: preload, create: create, update: update});var bubble1, bubble2, bubble3, bubbles;function preload() { game.load.image('bubble1', 'assets/bubble1.png'); game.load.image('bubble2', 'assets/bubble2.png'); game.load.image('bubble3', 'assets/bubble3.png');}function create() { game.stage.backgroundColor = '#ccc'; game.physics.startSystem(Phaser.Physics.ARCADE); bubble1 = game.add.sprite(50, game.world.height - 50, 'bubble1'); bubble2 = game.add.sprite(200, game.world.height - 50, 'bubble2'); bubble3 = game.add.sprite(350, game.world.height - 50, 'bubble3'); bubbles = game.add.group(); bubbles.add(bubble1); bubbles.add(bubble2); bubbles.add(bubble3); bubbles.enableBody = true; bubbles.setAll('anchor.x', 0.5); bubbles.setAll('anchor.y', 0.5); bubbles.forEach(function (bubble) { game.physics.arcade.enable(bubble); bubble.body.collideWorldBounds = true; bubble.body.bounce.set(1); }); bubble1.body.velocity.setTo(200, 200); bubble2.body.velocity.setTo(250, 250); bubble3.body.velocity.setTo(100, 200);}function update() { game.physics.arcade.collide(bubbles, bubbles);} Link to comment Share on other sites More sharing options...
rich Posted August 1, 2015 Share Posted August 1, 2015 Are your bubbles round? Are you sure what you're seeing isn't just the results of arcade physics using AABBs for all collision, not circles? Link to comment Share on other sites More sharing options...
finspin Posted August 2, 2015 Author Share Posted August 2, 2015 Yes, I think my problem is that the bubbles are in fact not rounded but they are seen as squares. I have uploaded my example here http://finspin.github.io/bubble-game/. Could you please point me to the right direction how to achieve collision of rounded objects? Link to comment Share on other sites More sharing options...
AzraelTycka Posted August 2, 2015 Share Posted August 2, 2015 Try P2 physics instead of arcade. Link to comment Share on other sites More sharing options...
Recommended Posts