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
  3. Dismiss Notice

Question Small collider doesn't detect trigger collisions with bigger collider

Discussion in 'Physics' started by dichtermut, Jan 16, 2024.

  1. dichtermut

    dichtermut

    Joined:
    Jul 21, 2018
    Posts:
    26
    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().

    upload_2024-1-16_13-7-14.png

    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...
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,909
    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.
     
    dichtermut likes this.
  3. marcoantap

    marcoantap

    Joined:
    Sep 23, 2012
    Posts:
    252
    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.
     
    dichtermut likes this.
  4. dichtermut

    dichtermut

    Joined:
    Jul 21, 2018
    Posts:
    26
    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.
     
  5. marcoantap

    marcoantap

    Joined:
    Sep 23, 2012
    Posts:
    252
    Last edited: Jan 17, 2024