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).
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.)?
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.
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?
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:
Convex hull:
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!
1 Like