Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Mesh colliders aren't scaled properly with parent

Discussion in 'Editor & General Support' started by Arsonistic, Apr 20, 2018.

  1. Arsonistic

    Arsonistic

    Joined:
    Dec 11, 2016
    Posts:
    13
    I'm trying to scale a bunch of small parts by just scaling the parent, but somehow the mesh colliders don't scale properly and no longer adhere to the rendered mesh. The problem doesn't happen when rigidbodies are set to Kinematic and it disappears the moment you update any kind of scaling on the parent or objects in the editor (during play).
    I've uploaded pictures showing before and after slight scaling change (which somehow updates the colliders to become correct).
     

    Attached Files:

  2. Arsonistic

    Arsonistic

    Joined:
    Dec 11, 2016
    Posts:
    13
    I think I just found the root cause of the issue:
    For some reason the small(child) parts are rotated slightly before being scaled, when they really shouldn't (through some bug?), and only the visible mesh is scaled with this rotation, the mesh collider uses the un-rotated(correct) mesh.

    I've come up with a work-around that takes the parent scaling and applies it to the children through a script, but it's kind of a pain and really shouldn't be an issue in the first place.

    Not sure if I should make a thread about this (with a more fitting title) to get the attention of somebody working for Unity in the hope of fixing the bug.
    I can provide a screenshot of the rotation bug if anybody wants one (only visible in play mode, happens on first frame, clearly visible when starting paused).
     
  3. angelonit

    angelonit

    Joined:
    Mar 5, 2013
    Posts:
    40
    This also happens to me: I have an asteroid that breaks in a lot of pieces, the asteroid has a random scale and every piece of it has a rigidbody that rotates with the asteroid breaking, the mesh colliders only stay in mesh if the parent's scale is equal in every axis
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,711
    Non-uniform scaling is kind of a dead end a 4x4 transform hierarchy.

    Basically there's no way to rotate a non-uniform scale without keeping the entire "stack" of changes alive.

    Here's one solution:

    - pre-create a bunch of variations of your rock chunks, all different sizes, and use those (this is easiest)

    OR:

    - change the mesh itself while preserving uniform scaling (ideally identity scaling) for the Transform.

    If you want hints / pointers on doing this procedural generation, you're welcome to look through my MakeGeo package, just random procgen stuff.

    MakeGeo is presently hosted at these locations:

    https://bitbucket.org/kurtdekker/makegeo

    https://github.com/kurtdekker/makegeo

    https://gitlab.com/kurtdekker/makegeo

    https://sourceforge.net/p/makegeo