In the image you can see the Wall Mesh of my scene. The full mesh is one game object with a non-convex Mesh collider and a kinematic rigidbody.
On the other hand there’s the projectiles, which are static trigger colliders (no rigidbody, sphere collider with IsTrigger set to true).
The projectiles normally hit the Walls as intented, but some of them (maybe 1/100) go right through them without triggering Projectile.OnTriggerEnter().
I thought that maybe it had to do with the radius of the sphere collider in the projectiles, which is quite small (0.05), and after changing it to 0.12, there’s been a significant improvement in the number of “ghost projectiles”. However, some of them still keep going through walls. Why does this happen? Any idea how could I avoid it?
PS. If I make the spehere collider bigger enough (radius=0.25) it seems like no projectiles go throught the walls, but I would like to use a smaller collider…
If they are moving quite fast you may be observing a quantum tunneling effect. Basically one frame the collider is fully outside, next frame it is fully inside (or passed through). Then no collision triggers.
The solution is continuous collision detection. This comes at a cost, and this cost is likely higher in your case because mesh colliders are inefficient to begin with and more so if they are concave. You gotta test this on the target platform. Ideally you should construct your collision geometry using primitives, ie boxcolliders.
1 Like
Continuous dynamic is better for high speed objects, and speculative is less expensive but isn’t very precise if you need to get the exact point of collision.
1 Like
Thank you both for your answers. I tried all three continuous collision detection available options in my Unity version and ‘continuous dynamic’ was the best one, but it still allowed some of the projectiles going through. It seems weird to me, since in my view they’re not moving that incredibly fast (20 * Time.deltaTime).
However, thanks to you pointing out the tunneling effect, I opted for extending the collider in the Z-axis, so that the Wall collider has more chances to detect the collision.
Yes, it isn’t perfect and it’s actually pretty easy to get objects going thru walls or vibration when in between walls, which is concerning. Unity offers another physics library you might want to try out (requires Unity Pro or better):
https://docs.unity3d.com/Packages/com.havok.physics@1.0/manual/index.html