Search Unity

Question Collision happens when colliders too close to each other

Discussion in 'Physics' started by kader1081, May 12, 2023.

  1. kader1081

    kader1081

    Joined:
    Oct 16, 2021
    Posts:
    379
    Hi there is a 2 object they have square colliders set to trigger. Box collider size is 0.31 0.31 normally it is 0.32 but i made 0.31 for leaving a little bit gap but collision still happens. I have to set collider size to 0.29 for preventing collision Sprite-0002.png
     
  2. devPatrick

    devPatrick

    Joined:
    Sep 28, 2018
    Posts:
    22
    You're probably going to want to use a combination of larger scale, smaller collider size, and default contact offset.

    If the scale of your game environment and objects is larger, you won't notice as much the small gap between objects where they're still separated, but triggering collision.

    If you make your collider smaller than the render component, your render components can get closer before triggering collision. Depending on how much smaller you make the collider, you may also experience some penetration between the render components.

    You can reduce the default contact offset in Project Settings/Physics/Default Contact Offset or Project Settings/Physics 2D/Default Contact Offset (depending on whether you're making a 2D or 3D game). You should read the tooltip and documentation so you know the consequences of changing this value. If you do use this, my suggestion would be to make relatively small changes. It's 0.01 by default. I wouldn't go below 0.001.
     
    kader1081 likes this.
  3. kader1081

    kader1081

    Joined:
    Oct 16, 2021
    Posts:
    379
    I did the same thing but what i afraid of is enemies may stuck in gap