3ddy Posted April 21, 2016 Share Posted April 21, 2016 Hello, it's my first contact with Phaser physics. I have a ball sprite this.ball = game.add.sprite(x, .y, "ball"); I created a group with obstacles: this.obstacle = game.add.group(); this.obstacle.x = 700; this.obstacle.y = 350; var line = game.add.sprite(0, 0, "line"); line.anchor.setTo(0.5, 0); this.obstacle.addChild(line); line = game.add.sprite(0, 0, "line"); line.anchor.setTo(0.5, 0); line.angle = 90; this.obstacle.addChild(line); line = game.add.sprite(0, 0, "line"); line.anchor.setTo(0.5, 0); line.angle = -90; this.obstacle.addChild(line); game.physics.enable(this.obstacle, Phaser.Physics.ARCADE); for (var i = 0; i < this.obstacle.children.length; i++) { game.physics.enable(this.obstacle.children[i], Phaser.Physics.ARCADE); this.obstacle.children[i].body.angularVelocity = 30; } Then in update function I'm checking for collisions: update: function(){ var obstacleHit = false; game.physics.arcade.overlap(this.ball, this.obstacle, function(ball, obstacle){ if(!obstacleHit){ obstacleHit = true; } }, null, this); if (obstacleHit) { this.ball.destroy(); } }, But it works only with one of my three obstacles (don't know which one exactly because they are all the same, close to each other). In other words, it founds collision only on one of three sprites in my this.obstacle group. What am I doing wrong? I was trying with creating different names (line1,line2,line3) but I guess it didn't change anything. EDIT: I have found what may be wrong Collisions are working but only at the place where I spawned my obstacles, not against they current position (they are rotating, body.angularVelocity is set to 50). Any advice? Link to comment Share on other sites More sharing options...
drhayes Posted April 21, 2016 Share Posted April 21, 2016 Arcade physics doesn't work with rotating bodies. It only works with axially-aligned bounding boxes (AABBs). If you need more complex interactions you should check out P2 physics. Link to comment Share on other sites More sharing options...
Recommended Posts