Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

ApplyExplosionForce bug with collision filter

Discussion in 'Physics for ECS' started by argibaltzi, Oct 10, 2020.

  1. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    204
    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
    Code (CSharp):
    1. if (Input.GetKeyDown(KeyCode.Space))
    2.         {
    3.             Entities.WithBurst().ForEach((ref PhysicsVelocity velocity,
    4.               in PhysicsCollider collider, in PhysicsMass mass,
    5.               in Translation position, in Rotation rotation) =>
    6.             {
    7.                 velocity.ApplyExplosionForce(
    8.                     mass, collider, position, rotation,
    9.                     1000, new float3(0, -1, 0), 20,
    10.                     deltaTime, up);
    11.  
    12.             }).ScheduleParallel();
    13.         }

    If i change CollidesWith: Everything then it works fine...

    Is this a bug or am i missing something?
     
    steveeHavok likes this.
  2. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    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.
     
    petarmHavok likes this.
  3. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    204
    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
     
    petarmHavok likes this.