how to modify a collision filter during game

Hi,

I’m searching how to modify the collison filter during game. By the forum, i have find this (physics.removeBody and addBody ) But that don’t work. have you a better solution ?

local littleCharacterCollisionFilter = { categoryBits=2, maskBits=3 } -- the default behavior local characterCollisionFilter = { categoryBits=4, maskBits=5 } -- the next behavior --event.other have the littleCharacterCollisionFilter local function onCollisionBetweenCharacterAndLittle( event )     target=event.target     if ( event.phase == "began" ) then         if ( event.other.myid == 4 and event.other.isVisible ) then             physics.removeBody(event.other)             physics.addBody( event.other, { density=.5, friction=1, bounce=0.7,shape=pentagonShape, filter=characterCollisionFilter } )         end     end end character:addEventListener( "collision", onCollisionBetweenCharacterAndLittle )

Hi @espace3d,

You can’t change collision filters after instantiation of the body. There are, of course, some semi-advanced ways to workaround this, but can you please describe your goal/purpose for this need?

Thanks,

Brent

hi,

In fact i would that my littlecharacter fall from the game after hiting x time a border. I hope i was clear.

Why won’t setting collision filters initially accomplish your need?

Brent

Hi,

Because in the firt time, my character bounce to the borders and after x collisions my character fall so my character is no longer restrained by borders.

So i must reset my collision filter…

You could try setting the character physics body’s sensor value to true after x amount of collisions. That will allow it to pass through other physics objects.

ok Alex@Panc i will try at home.

Thanks.

Hi @espace3d,

You can’t change collision filters after instantiation of the body. There are, of course, some semi-advanced ways to workaround this, but can you please describe your goal/purpose for this need?

Thanks,

Brent

hi,

In fact i would that my littlecharacter fall from the game after hiting x time a border. I hope i was clear.

Why won’t setting collision filters initially accomplish your need?

Brent

Hi,

Because in the firt time, my character bounce to the borders and after x collisions my character fall so my character is no longer restrained by borders.

So i must reset my collision filter…

You could try setting the character physics body’s sensor value to true after x amount of collisions. That will allow it to pass through other physics objects.

ok Alex@Panc i will try at home.

Thanks.