Search Unity

why does a collider with 0 scale still take collisions?

Discussion in 'General Discussion' started by Mike01923, Mar 21, 2023.

  1. Mike01923

    Mike01923

    Joined:
    Jun 19, 2015
    Posts:
    195
    I assumed when I scale something to 0, the collider won't be colliding with things, but that's not the case. Why is that?
     
  2. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,160
    Because it's still something that exists as a point in 3D space.
     
    angrypenguin and Homicide like this.
  3. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,573
    Because a body with size 0 will still be a point in space. While a point has no volume, it is reasonable to expect it to be impassable.

    If you want to disable collision, disable the collider. Also, do not "assume", read the docs. If the docs do not say "size zero colliders won't collide", then no such feature exists.
     
    DungDajHjep likes this.
  4. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    It's a perfectly good question, and intuitively I can see why you'd expect something scaled to nothing to not collide. It's not really nothing, though.

    Setting scale to zero effectively multiplies the local position of every vertex (or the size of every primitive) by zero. This doesn't stop them from existing, it just puts them all in the same spot. That doesn't change the outcome of the math that checks intersections. It just makes one body equivalent to a point.

    It's perfectly valid, and common, to check collisions between an object and a point.

    Even if it wasn't, as a programmer I would expect a zero-scaled collider to still collide with things, for a few reasons. I don't expect the physics engine to be checking if, say, vertices in a mesh collider are in the same spot and then behaving differently, because that would both incur a computational cost and make behaviour less consistent. There may be valid reasons to scale something to 0 and still check collisions, or for an object to just legitimately be tiny in some cases, and this helps 0 be consistent with other cases.

    In other words, while it may be initially counter-intuitive for something which has disappeared to still be solid, it saves a bunch of work addressing edge cases which would otherwise exist, while adding trivial requirements (changing one variable) to address the opposite behaviour where it's desired.