KyhmeBiatches Posted May 4, 2016 Share Posted May 4, 2016 I'm trying to get a callback, when the player hits the door, but nothing happens... It drives me crazy now, and I don't know why this doesn't work, cause I think it should. This is what i have under create: //Load player //1700 playerSprite = this.game.add.sprite(50, 900, 'player-front'); player = new Player(playerSprite); //Physics this.game.physics.startSystem(Phaser.Physics.P2JS); //Setting up witch tiles needs colliders map.setCollision(261, true, 'Collisions'); this.game.physics.p2.convertTilemap(map, 'Collisions'); this.game.physics.p2.enable([player.sprite], true); player.sprite.body.fixedRotation = true; //Physics engine create collision bodies from the tiles this.game.physics.arcade.enable(map); this.game.physics.setBoundsToWorld(); this.game.physics.p2.setImpactEvents(true); var playerCollisionGroup = this.game.physics.p2.createCollisionGroup(); var doorCollisionGroup = this.game.physics.p2.createCollisionGroup(); this.game.physics.p2.updateBoundsCollisionGroup(); var doors = this.game.add.group(); doors.enableBody = true; doors.physicsBodyType = Phaser.Physics.P2JS; var door = doors.create(350, 865, 'player-back'); door.body.setRectangle(40,60,0,0); door.body.debug = true; door.body.setCollisionGroup(doorCollisionGroup); door.body.collides(playerCollisionGroup); player.sprite.body.setCollisionGroup(playerCollisionGroup); player.sprite.body.collides(doorCollisionGroup, this.hitDoor); And this is my hitDoor function: hitDoor: function(body1, body2){ console.log("Does this work??"); }, What am I doing wrong? Ty. Link to comment Share on other sites More sharing options...
agogiam Posted May 10, 2016 Share Posted May 10, 2016 Looks like you are trying to mix Arcade and P2. You should try setPostBroadphaseCallback if you want to custom define your collision responses. Link to comment Share on other sites More sharing options...
Recommended Posts