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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Box collider not aligning with mesh during rotation

Discussion in 'Physics' started by demskilz, Jan 9, 2018.

  1. demskilz

    demskilz

    Joined:
    Jan 9, 2018
    Posts:
    2
    Can anyone please explain why my box collider (attached to the bone) is not aligning with the mesh during rotation? Attached images
    Normal state.png Rotation state.png
     
    hyouuu likes this.
  2. sobanarshad85

    sobanarshad85

    Joined:
    Jan 9, 2018
    Posts:
    5
    apply a rigidbody to the object, according to your needs make it isKinematic on/off or gravity on/off. it'd be more better if you keep your script on empty game object and place your object in that empty one, and apply all the thing on that empty game object, thingd = colliders, rigid body etc etc, not tested yet, and if this doesnt work then apply your collider on original object and rest properties on empty game object, that is now parent object, hope you are answered. if not answered then hit me back, i'll then test the thing and will tell you.
     
  3. demskilz

    demskilz

    Joined:
    Jan 9, 2018
    Posts:
    2
    Hey thanks for taking the time to reply. I tried whatever you mentioned but the rotation is still happening the same way. I actually imported the object from blender with an animation. Since I want the box collider to follow the mesh during animations, I had to add rigid body and box collider to the bone. I am now beginning to think there might be some problem with the original blender file itself. Please let me know if you have any ideas or insights.
     
  4. sobanarshad85

    sobanarshad85

    Joined:
    Jan 9, 2018
    Posts:
    5
    recently same issue was occuring to my mate, with animation i dont know how to make it work, we tried hard though, if animation is only of rotation then i'll must say dont use animation try to rotate it with code, this way it'll work correctly
     
  5. hyouuu

    hyouuu

    Joined:
    Nov 26, 2020
    Posts:
    42
    @demskilz did you figure out how to fix it? Facing the same issue
     
  6. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    464
    Pretty sure there are non-uniform scales in your transform hierarchy. Set up your hierarchy only using game objects with scale = (1,1,1) and then parent your scales visual objects to the bones.
     
  7. hyouuu

    hyouuu

    Joined:
    Nov 26, 2020
    Posts:
    42
    Thanks @tjmaul. However, do you know why scales are not supported with the colliders? Shouldn't they be?
     
  8. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    464
    Uniform scales are supported, which means all the scale values are the same. Non-uniform scales are supported by the box collider. Be aware that non-uniform scales and rotations cause skew down the transform hierarchy, so just stick to uniform scales. This is really just a problem if you're using the built-in box mesh to approximate cuboids.
     
    hyouuu likes this.
  9. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,633
    No existing engine supports this, because of basic matrix math: if you compose a rotation and a scale matrix, the resulting transform is shear/skew: https://en.wikipedia.org/wiki/Shear_mapping

    Also, Unity's manual warns you about this:
    https://docs.unity3d.com/Manual/class-Transform.html

     
    hyouuu likes this.
  10. hyouuu

    hyouuu

    Joined:
    Nov 26, 2020
    Posts:
    42
    Thanks for the replies - new knowledge learned :)