sagnew Posted December 14, 2014 Share Posted December 14, 2014 Hey im having collision issues between groups. I have a playerGroup, enemyGroup, playerSword, and enemySword. For some reason the collision is being detected between the enemy's swordGroup and the playerGroup. Collision is also being detected between the player and enemy group but the playerSword is not being detected by the enemyGroup or the enemySword. Here is some of my code. I would greatly appreciate the help! create: function(player_Id) { maingroup = this.engine.add.group(); mainsword = this.engine.add.group(); // maingroup taking engine properties this.sprite = maingroup.create(0, 0, 'fighter'); this.sword = mainsword.create(50, 50, 'sword'); var sprite = this.sprite; var engine = this.engine; var sword = this.sword; engine.physics.startSystem(Phaser.Physics.ARCADE); engine.physics.arcade.enable(sprite); engine.physics.arcade.enable(sword); sword.anchor.setTo(-.05, 7); sprite.addChild(sword); sprite.body.bounce.y = 0.1; sprite.body.gravity.y = 500; sprite.body.collideWorldBounds = true; sprite.animations.add('left', [7, 8, 9, 10, 11, 12], 10, true); sprite.animations.add('right', [0, 1, 2, 3, 4, 5, 6], 10, true); sprite.animations.add('still', [5]); cursors = engine.input.keyboard.createCursorKeys(); attackButton = engine.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); update: function() { var sprite = this.sprite; var engine = this.engine; var sword = this.sword; sprite.body.velocity.x = 0; sword.body.velocity.x = 0; engine.physics.arcade.collide(enemygroup, maingroup); engine.physics.arcade.collide(sword, enemygroup); //engine.physics.arcade.collide(mainsword, enemygroup); Enemy File: create: function(player_Id) { enemygroup = this.engine.add.group(); enemysword = this.engine.add.group(); // maingroup taking engine properties this.sprite = enemygroup.create(200, 200, 'fighter'); this.sword = enemysword.create(50, 50, 'sword'); var sprite = this.sprite; var engine = this.engine; var sword = this.sword; engine.physics.startSystem(Phaser.Physics.ARCADE); engine.physics.arcade.enable(sprite); engine.physics.arcade.enable(sword); engine.physics.arcade.enable(enemysword); sword.anchor.setTo(-.05, 7); sprite.addChild(sword); update: function() { var sprite = this.sprite; var engine = this.engine; var sword = this.sword; // console.log(mainsword); sprite.body.velocity.x = 0; sword.body.velocity.x = 0; engine.physics.arcade.collide(sword, maingroup); // engine.physics.arcade.collide(enemygroup, maingroup); // engine.physics.arcade.collide(mainsword, maingroup); } Link to comment Share on other sites More sharing options...
Recommended Posts