[Solved] How can I compensate the impossibility to change collision filter during the game?

Hi.

I’m facing this problem: in the game I’m making, when the main character touches an enemy (and lose some life), he becomes invincible for a few seconds. During this time I need the physics engine to not consider any collision between the main character and enemies, as he must be able to pass through them.

Now, I see corona does not allow to change the collision filter parameter during the game, so I have to find some other way.

I can not change the isSensor value of either the main character or the enemy, as they need to keep having collision with other objects.  One possible solution would be destroy and re-make the physic body with a different filter parameter, but I’m afraid this could be performance killing.

Another thing I thought is apply a multi elements body to the main character, where the two identical bodies has different filters, but don’t know any way to activate and deactivate body elements during the game.

If I could for example apply the isBodyActive function to a specific body element, or change its isSensor parameter, the problem would be solved.

Any ideas?

Ok, found a solution, I share it in case anyone would have the same problem.

The solution was kind of easy :slight_smile: just using physicsContact.isEnabled on a pre-collision event. Here are some details: https://docs.coronalabs.com/api/type/PhysicsContact/isEnabled.html

Thanks for sharing that.  I have used the “double body” method in the past as a collision quick fix but I should have dug a little deeper and used this more elegant pre-collision solution  :wink:

Ok, found a solution, I share it in case anyone would have the same problem.

The solution was kind of easy :slight_smile: just using physicsContact.isEnabled on a pre-collision event. Here are some details: https://docs.coronalabs.com/api/type/PhysicsContact/isEnabled.html

Thanks for sharing that.  I have used the “double body” method in the past as a collision quick fix but I should have dug a little deeper and used this more elegant pre-collision solution  :wink: