Collision trigger events are sometimes delayed

I’ve looked into it a bit. So, its one of those unfortunate downsides of using a rigidbody as a trigger. Basically, Ammo is calculating the contact data in the dynamics world and depenetrate objects by pushing them outwards. For efficiency, it caches the contact points in a persistent manifold cache. Since PlayCanvas is using a rigidbody instead of ghost objects, Ammo calculates all the contact info for triggers as it would for normal bodies, caching the contacts. That cache can live pretty long, giving you long living contacts that you experience.

So, first option is that you clear the persistent manifold cache, if one of the two objects in the contact manifold is a trigger. Clearing a manifold cache is not exposed to Ammo, unfortunately, so you would have to create a custom Ammo build to do that.

Another option would be to set a contact breaking threshold on the persistent manifold. This will auto remove a contact from the cache, if the bodies are further apart than given threshold value. This is also not exposed in Ammo, unfortunately, and you’d have to create a custom Ammo build as well :frowning:

If you do go for custom build, then clearing the manifold cache should be the preferred one for your case probably, as you don’t have dynamic simulations.

Another option is to use a ghost object, instead of a rigidbody with bitmask as a trigger. This will avoid contact manifold alltogether and won’t have that issue. The good news is that the current Ammo version supports ghost objects, and you don’t need to build a custom version. The bad news is that PlayCanvas doesn’t use them, so you would have to implement them yourself, using Ammo API directly.

None of the options are easy to approach, I’m afraid. I’m working on a Jolt physics integration with PlayCanvas, which will be released soon. So, perhaps you could switch to that once its out.

1 Like