Zackorz Posted March 6, 2016 Share Posted March 6, 2016 hello guys, Im trying to implement collision detection to my game, // i Activate the physics system in my "create" function: myGame.physics.startSystem(Phaser.Physics.P2JS); myGame.physics.p2.setImpactEvents(true); // Now im defining the "colliding" objects in my "update" function: if (myGame.physics.arcade.collide(collider1, collidor2)) { console.log("collision"); } What is missing/ what im doing wrong? I never get any collision feedback, when the objects touch each other. Link to comment Share on other sites More sharing options...
lukaMis Posted March 6, 2016 Share Posted March 6, 2016 You are starting P2JS physics system and than checking for collide with arcade physics system. You can only have one system active in Phaser. Zackorz 1 Link to comment Share on other sites More sharing options...
Zackorz Posted March 6, 2016 Author Share Posted March 6, 2016 5 hours ago, lukaMis said: You are starting P2JS physics system and than checking for collide with arcade physics system. You can only have one system active in Phaser. Ok thanks. I tried it with " P2JS" now, but i cant figure out what im doing wrong. Here is my code: create: this.physics.startSystem(Phaser.Physics.P2JS); this.physics.p2.setImpactEvents(true); this.physics.p2.restitution = 0.8; var playerCollisionGroup = this.physics.p2.createCollisionGroup(); var cloudCollisionGroup = this.physics.p2.createCollisionGroup(); this.physics.p2.updateBoundsCollisionGroup(); var clouds = this.add.group(); clouds.enableBody = true; clouds.physicsBodyType = Phaser.Physics.P2JS; var smallcloud= clouds.create(300, 300, 'Cloudpicture'); smallcloud.body.setRectangle(40, 40); smallcloud.body.setCollisionGroup(cloudsCollisionGroup); bird = this.add.sprite(this.world.centerX, this.world.centerY/1.5, "mysprite"); bird.anchor.setTo(0.5, 0.5); bird.enableBody = true; bird.physicsBodyType = Phaser.Physics.P2JS; bird.body.setCollisionGroup(playerCollisionGroup); // here i get an error: "cannot read property CollisionGroup of null" What is wrong with this line ? I think i programmed it like in the phaser "group collision example" Link to comment Share on other sites More sharing options...
Zackorz Posted March 7, 2016 Author Share Posted March 7, 2016 i added: this.physics.p2.enable(bird, false); now its working, but this line destroys all movement of my bird. I have a "tween" movement on my bird, that is triggered when i click somewhere. Why is this gone now??? The rest of my game is also broken , both physics objects are flying around like crazy now.. Link to comment Share on other sites More sharing options...
lukaMis Posted March 7, 2016 Share Posted March 7, 2016 Tweens and physics do not mix particularly well. If you use physics system you should move your objects with physics forces not tweens. If you need physics just for collisions u can use overlap instead and move objects with tweens. Zackorz 1 Link to comment Share on other sites More sharing options...
Zackorz Posted March 7, 2016 Author Share Posted March 7, 2016 8 hours ago, lukaMis said: Tweens and physics do not mix particularly well. If you use physics system you should move your objects with physics forces not tweens. If you need physics just for collisions u can use overlap instead and move objects with tweens. Ok thanks, i will give it a try :-) Link to comment Share on other sites More sharing options...
Recommended Posts