Hello everyone,
in my game I often want to if the player collides with an enemy that he loses an lives and becomes temporary invulnerable. Because of this invulnerability I want him to be able to walk through the enemies for short time and the collision should not have any physical effect on the player.
I have some ideas how I can do it, but I think that there are probably better / more straightforward solutions.
My approach would be to have an duplicate version of every fixture.
The first instance of the fixture has a collisioncategory/maskbits, so that it will only collide with things like walls (not enemies!).
The second fixture instance is a sensor, which collides with enemies only.
When the second fixture has a collision (which then must be with an enemy), I will change the collisioncategory/maskbits so that this fixture instance won't collide with anything until the player is vulnerable again.
This approach might work, but it has some serious problems:
- It's complex
- I need to duplicate every fixture
- The type of reaction to a collision (if force should be applied or not) must be defined, before the actual collision happens, so it will be difficult to to change this behaviour based on volatile information
Is there a better way to do this?
Thanks for your help in advance!
in my game I often want to if the player collides with an enemy that he loses an lives and becomes temporary invulnerable. Because of this invulnerability I want him to be able to walk through the enemies for short time and the collision should not have any physical effect on the player.
I have some ideas how I can do it, but I think that there are probably better / more straightforward solutions.
My approach would be to have an duplicate version of every fixture.
The first instance of the fixture has a collisioncategory/maskbits, so that it will only collide with things like walls (not enemies!).
The second fixture instance is a sensor, which collides with enemies only.
When the second fixture has a collision (which then must be with an enemy), I will change the collisioncategory/maskbits so that this fixture instance won't collide with anything until the player is vulnerable again.
This approach might work, but it has some serious problems:
- It's complex
- I need to duplicate every fixture
- The type of reaction to a collision (if force should be applied or not) must be defined, before the actual collision happens, so it will be difficult to to change this behaviour based on volatile information
Is there a better way to do this?
Thanks for your help in advance!