Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

[Solved] How can I compensate the impossibility to change collision filter during the game?
Started by Loner Cat Jun 04 2018 06:34 AM

2 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Loner Cat

[GLOBAL: userInfoPane.html]
Loner Cat
  • Enthusiast

  • 33 posts
  • Corona SDK

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?



[TOPIC: post.html]
#2

Loner Cat

[GLOBAL: userInfoPane.html]
Loner Cat
  • Enthusiast

  • 33 posts
  • Corona SDK

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

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


  • sporkfin likes this

[TOPIC: post.html]
#3

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 415 posts
  • Corona SDK

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  ;)




[topic_controls]
[/topic_controls]