PansenDarmVirus Posted March 25, 2016 Share Posted March 25, 2016 Hello there, I started using phaser a week ago and for my starter project i need accurate collision detection - that means P2 engine yeaah! But i just dont need the default collisions with bouncing everything away. Basically all sprites/bodies should be static and on contact i want a custom function to do the job. The problem for me ist just, that as soon as both objects are static, no onBeginContact nor any similar event is triggered, as far as i know. Working against the physics movement and rotation following a collision is no option - so buggy So how can i receive a contact event without executing the default collision for at least one of the 2 objects? Why is this simple task so complicated? am i just stupid? Link to comment Share on other sites More sharing options...
PansenDarmVirus Posted March 29, 2016 Author Share Posted March 29, 2016 After struggling with this problem for quite some time i found a solution with the shape.sensor=true property. The tricky part here was, that Phaser splits a polygon into multiple shapes, which all require their personal sensor=true. So finally my code looks like: gemuese = this.add.sprite(42,42,"gurke"); this.game.physics.p2.enable(gemuese, true); gemuese.body.clearShapes(); gemuese.body.loadPolygon("collision_masks", "gurke"); for(var i=0; i<gemuese.body.data.shapes.length;i++)gemuese.body.data.shapes[i].sensor=true; gemuese.body.onBeginContact.add(fischfutter, this); fischfutter = function(body, bodyB, shapeA, shapeB, equation) { console.log("Heureka!"); } I suggest to include the polygon-split-up (or generally the contact without collision thing) into the p2 examples in some way at least, because- well, I wasn't the first with this kind of problem and probably won't be the last. See you guys Link to comment Share on other sites More sharing options...
Recommended Posts