Schuh Posted April 3, 2014 Share Posted April 3, 2014 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. Link to comment Share on other sites More sharing options...
valueerror Posted April 3, 2014 Share Posted April 3, 2014 you could set the body of the object that hit the player to static. object.body.static = true; do you really need physics for the game.. because overlaps can be calculated without physics.. and simlpe movements from top to bottom are a matter of y += 1 on every update cicle. still you could remove the collision completely between the player and the object and use the "intersects()" method to find out if they hit each other.. Link to comment Share on other sites More sharing options...
Schuh Posted April 4, 2014 Author Share Posted April 4, 2014 Thanks!Setting the body.static to true solved my problem.I'll need the physics later because I what to reset the shapes and use polygons for a pixel perfect collision. Link to comment Share on other sites More sharing options...
Recommended Posts