neoRiley Posted April 30, 2014 Share Posted April 30, 2014 I'd like to create a polygon collider that would define an "ice patch" and looking through the docs for p2.Body I can't seem to locate a property that would set a collider/body to be a "trigger" that would just give off enter/exit callbacks. Is there a way to do this with the p2 physics engine? Link to comment Share on other sites More sharing options...
george Posted April 30, 2014 Share Posted April 30, 2014 It's called a sensor and is a property of a fixture/shape in P2. You get the reference of a shape during the creation of it;circleShape = sprite.body.addCircle(radius)circleShape.sensor = trueNow with the right keyword at hand you can find a lot to the topic.http://www.html5gamedevs.com/topic/5567-trigger-with-p2/?hl=sensor#entry33612 Enjoy! Link to comment Share on other sites More sharing options...
neoRiley Posted April 30, 2014 Author Share Posted April 30, 2014 ah! yes, sensor would have helped! I read through that post, and wanted to confirm that this is what will work:sprite.body.data.shapes[0].sensor = true;So in my current code base, this should work? this.player.body.clearShapes();this.player.body.loadPolygon('carData', 'car');this.player.body.data.shapes[0].sensor = true;Thanks for your help! Link to comment Share on other sites More sharing options...
george Posted April 30, 2014 Share Posted April 30, 2014 No that's the only thing that will not work.A polygon is a composition of many many convex shapes. You have to iterate over all of them (in data.shapes) and set shape for shape as a sensor. Oooor you could try a feature that I added to Phaser some weeks ago. It's merged and available. You have to use another physics json format. Phaser Exporter for PhysicsEditor. It's located in the folder resources/PhysicsEditor Exporter. With this exporter you can set collision masks, collision categories, the sensor property and also give shapes an ID to retrieve them later by a name from the fixture list. There is no documentation or examples for these extended physics features available yet. That's my duty, I'm really searching for a calm day to do it. Try to get the custom exporter running (general infos: http://www.codeandweb.com/blog/2012/05/30/customize_physicseditor_exporter). You could then do it manually:fixtures = body.addPhaserPolygon('physics','polygonName')fixtureList = new Phaser.Physics.P2.FixtureList(fixtures)fixtureList.setSensor(true) or just use the sensor property in PhysicsEditor- it will create all shapes with sensor set to true Here an example from my current project. I define everything in PhysicsEditor. Collision & category bits, sensor flags. The view is zoomed as I can't show you asset details from that client project. Here the pull requests for some more details The PR for Phaser.Physics.P2.FixtureListhttps://github.com/photonstorm/phaser/pull/704 The PR for Phaser Physics Exporter:https://github.com/photonstorm/phaser/pull/614 RegardsGeorge Link to comment Share on other sites More sharing options...
neoRiley Posted April 30, 2014 Author Share Posted April 30, 2014 Yeah, that's perfect George! I was hoping that this level of information from PhysicsEditor could translate to Phaser. I tried setting sensor flag before and Phaser threw an error. Very cool, Thanks very much George! John Link to comment Share on other sites More sharing options...
neoRiley Posted May 1, 2014 Author Share Posted May 1, 2014 Hey George, I've downloaded the 2 files for use as the exporter for PhysicsEditor and restarted the app several times and I still don't see it in the drop down list. I've followed the instructions on their site ( http://www.codeandweb.com/blog/2012/05/30/customize_physicseditor_exporter ) and verified that they are named properly etc and it does not show up as an option. is there anything else I'm missing? Link to comment Share on other sites More sharing options...
george Posted May 2, 2014 Share Posted May 2, 2014 I guess you pointed directly into the folder with the two files exporter.xml & phaser.json ? That's wrong. You have to target the parent folder which contains the phaser exporter folder. But please don't target phaser/resources, you will get a lot of errors as PhysicsEditor tries to parse everything in there. Do it like I do it:Create somewhere a folder 'physics-exporters' and copy the folder 'PhysicsEditor Exporter' from phaser/resource in there. Rename it to 'phaser'. ./physics-exporters/phaser/exporter.xml./physics-exporters/phaser/phaser.json Now point to the folder ./physics-exporters Regards George Link to comment Share on other sites More sharing options...
neoRiley Posted May 2, 2014 Author Share Posted May 2, 2014 That worked great - thanks very much George! Link to comment Share on other sites More sharing options...
neoRiley Posted May 2, 2014 Author Share Posted May 2, 2014 And just to come full circle for others, this was the final code for getting my sensor poly called "ice": var fixtures = map.body.addPhaserPolygon("physicsData", "level");var fixtureList = new Phaser.Physics.P2.FixtureList(fixtures);this.ice = fixtureList.getFixtureByKey("ice"); Link to comment Share on other sites More sharing options...
Recommended Posts