Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    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:
    220
    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:
    220
    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.