Jump to content

Collisions are slightly off


finspin
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

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