Local_Minimum Posted May 1, 2014 Share Posted May 1, 2014 I'm very new to Phaser (<1 week) but I've stared at the examples and I think it really looks as if I'm doing the right thing, yet collisions refuse to work. In my gameState.create I run the following to set up my P2-physics: game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.setImpactEvents(true); game.physics.p2.restitution = 0.8; game.world.setBounds(-90, -300, 8200, 20000); this.playerCG = game.physics.p2.createCollisionGroup(); this.enemiesCG = game.physics.p2.createCollisionGroup(); this.groundCG = game.physics.p2.createCollisionGroup(); game.physics.p2.updateBoundsCollisionGroup();and later adding the player: this.player = game.add.existing( new Player(this, game, 750, 180, 0)); game.physics.p2.enable(this.player); this.player.body.setCollisionGroup(this.playerCG); this.player.body.collides(this.groundCG, this.player.collidesGround, this); this.player.body.collides(this.enemiesCG); my grounds are the 'fistulaeHair' and are added: game.physics.p2.enable(fistulaHair); fistulaHair.body.kinematic = true; this.ground.add(fistulaHair); fistulaHair.body.setCollisionGroup(this.groundCG); I'm expecting this.player.collidesGround to be called when flying into the ground but nothing happens: It doesn't collide the the collidesGround has a console.log as first line which never fires. I must be missing something very basic it feels like. Also, as a side question, how do I test if I hit the world-end in P2-physics? Any help much appreciated. Link to comment Share on other sites More sharing options...
valueerror Posted May 2, 2014 Share Posted May 2, 2014 player.body.collides(groundCG) and vice versa.. ground.body.collides(playerCG) then a collision should happen... it's confusing.. how can player collide with ground but ground NOT collide with player? never.. so we need to define both.. Link to comment Share on other sites More sharing options...
Local_Minimum Posted May 2, 2014 Author Share Posted May 2, 2014 Great! That was exactly my problem. You don't happen to know how I detect world-end-collision so that I can kill the object when it hits end of world (e.g. shots)? Link to comment Share on other sites More sharing options...
valueerror Posted May 2, 2014 Share Posted May 2, 2014 you need to enable worldbounds and then set outOfBoundsKill() on your sprite to true.. but this is heavy on the cpu.. maybe you could just set a lifeSpan on the sprites or detect when they leave the camera view with some if statements... Link to comment Share on other sites More sharing options...
Local_Minimum Posted May 2, 2014 Author Share Posted May 2, 2014 I'll check these solutions out, thanks for the help. Gamedev is alive again. Link to comment Share on other sites More sharing options...
Recommended Posts