Search the Community
Showing results for tags 'p2 physics collision abort'.
-
hey everyone! I'm new to phaser and I'm running into a little problem using the P2 physics engine: I have objects moving from top to bottom and the player at the very bottom (imagine a little shmup here). I want all of the objects to stop moving the moment the player touches either object. I've set up collisionGroups for the objects and the player and I've set a onBeginContact listener on the player's body. Problem is: everything stops just fine but the player and the object hit both keep moving slowly away from one another. I assume it's because the actual collision is being executed after the onBeginContact signal has been dispatched since setting both bodies' velocities to 0 doesn't help. Here is the full listener function I use: onPlayerCollision: function (body, shapeA, shapeB, equation){ // stop all hazards from scrolling this.hazards.setAll('body.velocity.y', 0); // prevent player from moving this.player.body.setZeroVelocity(); // stop the background tile scrolling this.ground.stopScroll(0, 0); // stop the timer this.timer.stop(true); // pause the update loop this.isRunning = false;},So my question is: is there a way to cancel the execution of the contact or do I need to take a completely different approach? I'd rather avoid using impacts since the docs say they're expensive. I saw that an array of equation objects is being passed to the hit function but I didn't find anything in the docs about what I could possibly do with these and the log output is a massive load of data.