Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Single collision can create multiple CollisionEvents

Discussion in 'Physics for ECS' started by ThomasEgan, Nov 22, 2019.

  1. ThomasEgan

    ThomasEgan

    Joined:
    Dec 17, 2013
    Posts:
    21
    In my testing I've discovered that a sphere to mesh collision (and possibly other combinations?) can create multiple CollisionEvents in a single frame (see example image).

    upload_2019-11-22_20-8-56.png

    Is this intended behaviour?

    If so is there a simple pattern to filter out extra collision events so I can easily respond to one collision of entity pairs per frame (for cases like spawning particles, applying damage etc.)?
     
  2. Rory_Havok

    Rory_Havok

    Joined:
    Jun 25, 2018
    Posts:
    70
    Yes this is intended behavior. The ball is in contact with multiple triangles,each applies its own separate impulse to resolve the collision, so each raises its own event.

    The engine doesn't currently have an option to return this as a single event. That would need some way to represent the merged info. Average contact position and average normal is one naive way - but it breaks down if you imagine the sphere the sitting in a V-shaped valley. For trigger events it makes more sense (but is also not currently an option) becuase we don't need the contact details there, but for collision events you typically do care about that info.

    So you would have to walk the stream of events (using an ICollisionEventsJob) and merge the collision events together using your own heuristic into a reduced stream of whetever info you need.
     
  3. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    Can I ask what your usecase is? Normally the object you are simulating with a mesh (broken pillar?), would be a single convex hull, in which case you would only receive a single collision. Also, the sphere is large when compared to individual triangles in the mesh. Does your usecase necessitate a large size ratio?
     
  4. ThomasEgan

    ThomasEgan

    Joined:
    Dec 17, 2013
    Posts:
    21
    My use case is having a fireball set fire to static geometry on collision. Whilst the pillar is easily represented by a convex hull something like the following bridge would need some kind of convex decomposition to be accurate.

    Mesh collider:
    upload_2019-11-23_18-47-56.png

    Convex hull:
    upload_2019-11-23_18-50-57.png

    That said I probably don't need the sphere to be so large and if I do I can look at detecting collisions via collider casts or filtering the collision event stream as Rory suggested. I was more just interested if this was intentional or not.

    Thanks for the quick response!
     
    steveeHavok likes this.