2 fixture Collision Behaviour

Hi, im modeling an bow and arrow game. I modeled the arrow using 3 fixtures: the tip , the body and the tail. The tip is set as a sensor and when it collides with the enemy, the enemy is destroyed, but the arrow must continue its original direction. My problem is that the enemy is colliding with the body of the arrow, even after the enemy is hit by the arrow tip. the side effect of this is that the arrow trajectory is changing after hitting some enemies. I check for collision imediately after the time step and as soon as a collision with the tip is detected the enemy is destroyed.

Why the enemiy still collides with the arrow body, even though it already collided with the tip and have been destroyed ?


Thanks
You should disable collision between the body and the enemies.
Look at the collision filtering testbed.

maybe something like :

Code:
uint16 ArrowBodyCategory     = 1 << 0;
uint16 ArrowSensorCategory   = 1 << 1;
uint16 EnemyCategory         = 1 << 2;

uint16 ArrowSensorMask       = EnemyCategory;
uint16 ArrowBodyMask         = 0xFFFF ^ EnemyCategory;
uint16 EnemyMask             = 0xFFFF ^ ArrowBodyCategory;
noon, thanks for reply...

but i need the body and tail of the arrow to colide with the enemy normally. Only if the tip of the arrow hits the enemy, the enemy is destroyed. If the tip of the arrow hit the enemy, it must be destroyed and the arrow must continue its original direction. but if only the body or the tail hits the enemy, the arrow must behave normally, changind its direction accordingly.

My problem is that Box2d is detecting collision with the arrow body (the fixture) after the enemy is hit by the tip. So, sometimes i shoot the arrow, the tip hits the enemy, but somehow the body fixture of the arrow also collides with the enemy, altering the arrow direction. my question is why it still collides with the second fixture of the arrow if as soon as i detect a collision in the tip i remove the arrow body ?
If I understand correctly, the collision between the body and the enemies sometime happens before the collision between the tip and the enemies.
My guess is that the collision of the tip and the body happens at the same frame because the arrow penetrated inside the enemy.

Have you tried to set the b2BodyDef bullet flag to true ? It may solve this issue since it would use continious collision detection and the tip would not penetrate.
I'm not sure if the bullet flag works with sensors. If not you may need to create a non-sensor fixture, and manage the collision response yourself inside the PreSolve method.

Also I wonder if simply changing the order of your fixtures inside the arrow would resolve your issue.
Maybe if you add the tip before the body then the test of the tip will be done before the test of the body.

Original thread: https://box2d.org/forum/viewtopic.php?t=5570