Search the Community
Showing results for tags 'firing'.
-
Hello, Making a basket ball game and I want to increase the score when I detect that the ball has been sunk in the basket. I place a rectangular sensor body under the net so it doesn't stop the ball from passing through it but can detect collisions. I create the sensor in the create() function: //Setting up checker physics this.game.physics.p2.enable(this.checker, true); this.checker.body.data.shapes[0].sensor = true; this.checker.body.static = true; And I add this onBeginContact callback, also in the create() function: this.checker.body.onBeginContact.add(this.checkIfScored, this); And since I only want to increase the score if the ball is travelling downwards through the net: checkIfScored : function () { console.log(this.ball.body.velocity.y); if (this.ball.body.velocity.y > 0) { console.log("SCORED!"); this.score++; this.scoreText.setText('Score: ' + this.score); } } My problem is: onBeginContact is only firing on the ball's way up, but it doesn't fire again on the way down and I don't know why. You can see the image below of it's setup on the stage. I've been in and out of the forums, digging for an answer. Any help is very much appreciated!!
- 1 reply
-
- physics
- onbegincontact
- (and 5 more)
-
Description: Collect gems to earn money, avoid or KILL enemies, collect fuel and ammo, go as long as you can! Mobile friendly HTML5 game Author: el_scrambone Genre: Action, Adventure, Shooter Game Dimensions: 852 x 640 pixels Game Link: http://bap1.pe.hu/ If you have some questions or tips - go and tell it to me) will be glad to get some feedbacks! Screenshots: Video Trailer: