Search Unity

Collider Issues with Negative Scale

Discussion in 'Editor & General Support' started by cyro_349, Mar 29, 2012.

  1. cyro_349

    cyro_349

    Joined:
    Sep 29, 2011
    Posts:
    6
    Hey People,

    I've noticed a weird (repeatable) behaviour with the colliders (seems to be with all of them). Basically it seems to ignore the transforms scale when it comes to rotations. Also when a parent's transform has a negative scale (so just swapping from 1 to -1) the size of the collider on the child object seems to change (looks like it's related to which scale value is negative, so a box collider with a parent scale of -1 will have a smaller x size then one with a parent scale of 1. Also with a capsule collider along the Y-Axis, the height changes in the same manner).

    Method:
    Create a Game Object (parent)
    Create a second Game Object (chile) and add it as a child to the parent
    Add a Capsule Collider (size it so it's easily visible in the editor)
    Change the Z rotation on the child game object (to 20ish)

    Issues:
    Now if you change the x scale on the child from 1 to -1, the rotation of the collider isn't flipped
    Also, if you change the x scale of the parent from 1 to -1, the size of the collider seems to change

    Any idea on how I can get around this? I'm working on a 2D platformer and it would be nice if my collider would rotate with my characters body (regardless of the direction it's facing).

    Thanks in advance,

    ~Cyro
     
  2. Nintendrew

    Nintendrew

    Joined:
    Nov 5, 2013
    Posts:
    2
    That's bizarre... I was able to recreate your issue, and I think it might be related to an issue I'm having. Child objects just seem to do crazy stuff when the parent is scaled negatively. I've made a little test project with 2 rotating cubes (one inside a flipped parent, one not) and sent it in a bug report. Hopefully this can get some attention soon :(
     
  3. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Provided it's a real bug. Negative scale causes all kinds of problems. A cube scaled by (-1,-1,-1) is actually inside out, so collisions with this cube happen when an object *leaves* the cube. Also, non-uniform scales and rotation cause orthogonal axes to shear, and this means collisions do not happen as you expect them to. Unless you know exactly what you are doing, I'd always advise against using any kind of negative, or nonuniform scale in interactive games. These are not bugs, just how math works.

    See: http://forum.unity3d.com/threads/219366-issue-with-negatvie-scale-and-colliders-on-2d
     
    Violet-n-red likes this.
  4. Nintendrew

    Nintendrew

    Joined:
    Nov 5, 2013
    Posts:
    2
    I just got a reply from Unity QA that said they were able to recreate this issue and are forwarding it to developers. Cheers! :)

    Edit: @Graham, thanks for the advice :)