ApplyExplosionForce bug with collision filter

Hello

I have a strange bug with applying explosions with certain collision filters

BelongsTo: Blocks
CollidesWith: Everything (Except Blocks)

The following code doesn’t work when the filter is set to the above

if (Input.GetKeyDown(KeyCode.Space))
        {
            Entities.WithBurst().ForEach((ref PhysicsVelocity velocity,
              in PhysicsCollider collider, in PhysicsMass mass,
              in Translation position, in Rotation rotation) =>
            {
                velocity.ApplyExplosionForce(
                    mass, collider, position, rotation,
                    1000, new float3(0, -1, 0), 20,
                    deltaTime, up);

            }).ScheduleParallel();
        }

If i change CollidesWith: Everything then it works fine…

Is this a bug or am i missing something?

1 Like

The AppyExplosionForce function uses a distance query to calculate the distance from the explosion center to the body. The current implication is setting the pointDistanceInput.Filter to be the same as the bodyCollider.Value.Value.Filter. see com.unity.physics\Unity.Physics\Extensions\PhysicsComponentExtensions.cs
Hence, the block is filtering out the block!

This is being changed in the upcoming release to set the pointDistanceInput.Filter = CollisionFilter.Default. Alternatively, we could add a default parameter in CollisionFilter explosionFilter = CollisionFilter.Default to the function.

1 Like

Ok i see what is happening, i duplicated the function and added an extra parameter to set the collisionFilter.
maybe is better to have the option to make it more flexible and easier to understand

at the moment as it stands it looks like a bug

1 Like