Collision filter not working for chain bodies

I’m currently using the Corona Collision Filters plug-in and I’m unable to get collision filters to work with chain bodies.  Before I go through the trouble of remaking my filters the old way (with category bits ) to further test this problem, I’m wondering if this is an oversight in the plugin or a Boxed 2D limitation.  Anyone know?

I have a filter called “null” which sets to not collide with anything.  When I apply this to the chain body’s filter, nothing happens.

[lua]

        physics.addBody( terra.cent, “static”, – terra.cent is the center point of the object

            {

                chain=vertices2,

                connectFirstAndLastChainVertex = true,

                filter=mt.cf.null  – mt.cf is the pathway to the collision filters - null means no collisions

            } )

    ------------------------------

[/lua]

OK, I also noticed that I can’t add eventListeners to the chain body - or at least they don’t trigger collision reports even though they are active in the physics environment

[lua]

local function shoutOut( e )

    local name = e.other.name or " who knows?"

    print( “The ground is touching”, name )

end

terra.cent:addEventListener( “collision”, shoutOut )

[/lua]

I use chain bodies to make landscapes which, until now, have been simple barriers but now I’m trying to add some more complex behaviors and I’ve encountered the two issues above with chain bodies.  Any insights are appreciated, thanks everyone.

The collision filters and collision events work fine. I have one game that is completely built around them and I haven’t run into any issues. I personally always use the old school collision filters as described in the docs. You probably just have an oversight somewhere in your code or in the plugin.

Try out the following code. It should work as you described. I copied a simple collision event from the docs and added two settings for filterObject that you can try out.

 

local physics = require("physics") physics.setDrawMode( "hybrid" ) physics.start() -- uncomment one of these -- local filterObject = { categoryBits=1, maskBits=1 } -- maskBits=1 results in no collision with filterGround local filterObject = { categoryBits=1, maskBits=3 } -- maskBits=3 results in collision with filterGround local filterGround = { categoryBits=2, maskBits=1 } local function onLocalCollision( self, event ) if ( event.phase == "began" ) then print( self.myName .. ": collision began with " .. event.other.myName ) end end local ground = display.newRect( 240, 240, 320, 40 ) physics.addBody( ground, "static", {filter=filterGround} ) ground.myName = "ground" ground.collision = onLocalCollision ground:addEventListener( "collision" ) local rect = display.newRect( 240, 40, 80, 20 ) physics.addBody( rect, "dynamic", { chain={ -40,-10,40,-10,40,10,-40,10 }, connectFirstAndLastChainVertex = true, filter=filterObject } ) rect.myName = "rect" rect.collision = onLocalCollision rect:addEventListener( "collision" )

I’ve created an excel file for easy collision filter setup. If you need it, I can upload it here for you tomorrow.

Update: I tried giving both objects chain physics bodies and it seems that if both objects are made out of chains, then they don’t collide regardless of the collision filter values.

@XeduR, thanks!

OK, that explains chain bodies vs chain bodies.  I’ll pull up my old manual filters and see if I can get them to work with chain vs. standard bodies.  I’ll PM you about the excel sheet.  I have a system I set up but I’m always happy to try one that might be faster.  Thanks again!

As the forums don’t allow the uploading of excel files, if anyone else needs the file, just let me know. The file does the calculations and filter setups automatically. All that’s left is to rename any filter and add any character to a “category” or “collides with” cell and the file manages the rest.

You can zip up the excel file to attach it.

Click ‘more reply options’ below to upload it.

Brilliant as usual, Ed! :smiley:

Here it is, if someone needs it.

@XeduR  Thanks for the collision filter excel file.  It works great!  Unfortunately, I’m still having the problem but I’m fairly certain it is indeed a problem with my code and not a system glitch or oversight.  Some of my chain bodies have close to 1,000 vertices and I fear there is an overlap somewhere that is causing the errors.  I’ve checked them extensively mathematically and in hybrid mode but I just can’t come up with any culprits.

I’ll keep trying and thanks again for your input.

It was totally my error.  I hunted down the problems and resolved them.  Thanks for encouragement @Xedur!

OK, I also noticed that I can’t add eventListeners to the chain body - or at least they don’t trigger collision reports even though they are active in the physics environment

[lua]

local function shoutOut( e )

    local name = e.other.name or " who knows?"

    print( “The ground is touching”, name )

end

terra.cent:addEventListener( “collision”, shoutOut )

[/lua]

I use chain bodies to make landscapes which, until now, have been simple barriers but now I’m trying to add some more complex behaviors and I’ve encountered the two issues above with chain bodies.  Any insights are appreciated, thanks everyone.

The collision filters and collision events work fine. I have one game that is completely built around them and I haven’t run into any issues. I personally always use the old school collision filters as described in the docs. You probably just have an oversight somewhere in your code or in the plugin.

Try out the following code. It should work as you described. I copied a simple collision event from the docs and added two settings for filterObject that you can try out.

 

local physics = require("physics") physics.setDrawMode( "hybrid" ) physics.start() -- uncomment one of these -- local filterObject = { categoryBits=1, maskBits=1 } -- maskBits=1 results in no collision with filterGround local filterObject = { categoryBits=1, maskBits=3 } -- maskBits=3 results in collision with filterGround local filterGround = { categoryBits=2, maskBits=1 } local function onLocalCollision( self, event ) if ( event.phase == "began" ) then print( self.myName .. ": collision began with " .. event.other.myName ) end end local ground = display.newRect( 240, 240, 320, 40 ) physics.addBody( ground, "static", {filter=filterGround} ) ground.myName = "ground" ground.collision = onLocalCollision ground:addEventListener( "collision" ) local rect = display.newRect( 240, 40, 80, 20 ) physics.addBody( rect, "dynamic", { chain={ -40,-10,40,-10,40,10,-40,10 }, connectFirstAndLastChainVertex = true, filter=filterObject } ) rect.myName = "rect" rect.collision = onLocalCollision rect:addEventListener( "collision" )

I’ve created an excel file for easy collision filter setup. If you need it, I can upload it here for you tomorrow.

Update: I tried giving both objects chain physics bodies and it seems that if both objects are made out of chains, then they don’t collide regardless of the collision filter values.

@XeduR, thanks!

OK, that explains chain bodies vs chain bodies.  I’ll pull up my old manual filters and see if I can get them to work with chain vs. standard bodies.  I’ll PM you about the excel sheet.  I have a system I set up but I’m always happy to try one that might be faster.  Thanks again!

As the forums don’t allow the uploading of excel files, if anyone else needs the file, just let me know. The file does the calculations and filter setups automatically. All that’s left is to rename any filter and add any character to a “category” or “collides with” cell and the file manages the rest.

You can zip up the excel file to attach it.

Click ‘more reply options’ below to upload it.

Brilliant as usual, Ed! :smiley:

Here it is, if someone needs it.

@XeduR  Thanks for the collision filter excel file.  It works great!  Unfortunately, I’m still having the problem but I’m fairly certain it is indeed a problem with my code and not a system glitch or oversight.  Some of my chain bodies have close to 1,000 vertices and I fear there is an overlap somewhere that is causing the errors.  I’ve checked them extensively mathematically and in hybrid mode but I just can’t come up with any culprits.

I’ll keep trying and thanks again for your input.

It was totally my error.  I hunted down the problems and resolved them.  Thanks for encouragement @Xedur!