Bertram Posted May 9, 2014 Share Posted May 9, 2014 I can't seem to figure this one out... I have two groups, and I want to detect when they are colliding. But the test alert function is never triggered. I thought this should be possible?var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update});var testa, testb;function preload() { game.load.image('block', 'test.png');}function create() { game.physics.startSystem(Phaser.Physics.ARCADE); testa = game.add.group(); game.physics.enable(testa, Phaser.Physics.ARCADE); testa.enableBody = true; testa.create(400,100,'block'); testb = game.add.group(); game.physics.enable(testb, Phaser.Physics.ARCADE); testb.enableBody = true; testb.create(400,200,'block'); cursors = game.input.keyboard.createCursorKeys(); cursors.up.onDown.add(function(){ testb.y -=10; }, this); }function update() { game.physics.arcade.collide(testa, testb, test); }function test(){ alert("HIT");} Link to comment Share on other sites More sharing options...
Pedro Alpera Posted May 9, 2014 Share Posted May 9, 2014 Look at this example: http://examples.phaser.io/_site/view_full.html?d=arcade%20physics&f=group+vs+group.js&t=group%20vs%20group Link to comment Share on other sites More sharing options...
Bertram Posted May 9, 2014 Author Share Posted May 9, 2014 So when I change the collision check with an overlap check it worksgame.physics.arcade.overlap(testa, testb, test, null, this);But I why doesn´t the collide method work? Link to comment Share on other sites More sharing options...
stasuss Posted May 9, 2014 Share Posted May 9, 2014 May be because of the specifics of the physics engine? When using collide - objects are automatically separated. When using overlap - they does not. Additionally you are using direct movement setting object's y property, instead of using velocity. Link to comment Share on other sites More sharing options...
molo4nik111 Posted May 26, 2014 Share Posted May 26, 2014 Got the same problem. How to collide objects if they are groups? Like 2 character groups with parts of body in them. I need collision but needn't to be separate. Link to comment Share on other sites More sharing options...
David Posted May 27, 2014 Share Posted May 27, 2014 @stasuss is correct. Your collisions will not work properly if you directly manipulate the position vs setting the velocity or acceleration. Here's a link to a solution someone provided for a similar issue someone was having (they were tweening, but in the end this is just directly manipulating the position value).Also you can see Rich's explanation here: ...if you are tweening the sprite x/y values directly then its entirely possible you end up translating the sprite directly into another one and the collision code never picks this up, because it checks velocity and position and then separates based on those values, but tweening them directly would break the separation. Another possible solution could be using come from using customSeparateX/Y. However, I haven't actually used this yet. molo4nik111 1 Link to comment Share on other sites More sharing options...
Recommended Posts