Jump to content

Collider used as a trigger


neoRiley
 Share

Recommended Posts

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

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

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.

 

post-5762-0-41370900-1398887137.png

 

Here the pull requests for some more details

 

The PR for Phaser.Physics.P2.FixtureList

https://github.com/photonstorm/phaser/pull/704

 

The PR for Phaser Physics Exporter:

https://github.com/photonstorm/phaser/pull/614

 

Regards

George

Link to comment
Share on other sites

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?

 

2014-05-01_14-43-26.png

Link to comment
Share on other sites

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

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");
 
2014-05-02_11-02-20.png
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...