Search Unity

Moving mesh collider in relation to object

Discussion in 'Editor & General Support' started by i.phaedrus, Nov 23, 2009.

  1. i.phaedrus

    i.phaedrus

    Joined:
    Nov 23, 2009
    Posts:
    3
    Hello,

    I have built a simple room with some furniture and am trying to get physics collision going. It works fine with the box, sphere, capsule, but I'm wanting better accuracy, so I created a simple mesh (50verts 44 tri's) of a little footstool, but when i attach the mesh collider to the footstool, the collider is off center. how to I move/rotate just the collider to align with the object? I've tried importing the mesh collider object as .3dh, .obj .dae, and I've made sure the origin of the main footstool object is centered inside the object. I've also tried creating an empty game object, centering that on the main footstool object, then attaching the mesh collider to the game object, but it is still way off center.

    any help/suggestions are much appreciated. this is part of a project where we have integrated augmented reality marker with Unity if anyone is interested.

    thanks!
    -i.phaedrus
     
  2. i.phaedrus

    i.phaedrus

    Joined:
    Nov 23, 2009
    Posts:
    3
    I've also tried using the "generate collider" on the assets, but when i do, nothing seems to happen..

    thanks!
    i.phaedrus
     
  3. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    The coordinate space of the collider is the same local space used for the visible mesh geometry, so there isn't any way to move or rotate one relative to the other. If you add a mesh collider in Unity (menu Component > Physics > MeshCollider), then it should use the visible mesh geometry for the collider. Are you saying this isn't happening? (If your 3D app has an option to generate colliders, this won't be recognised by Unity.)
     
  4. i.phaedrus

    i.phaedrus

    Joined:
    Nov 23, 2009
    Posts:
    3
    I figured the coordinate spaces are shared - makes sense, but why is the mesh collider no where near the actual mesh... probably b/e the local coordinate space center point is not in the center of the object... will have to chase that down, i guess. i just wish there was a way to better manage center points in Unity. my 3d app allows me to very easily move the center axis of the object wherever i want. I can achieve this in unity by creating a new empty game object, centering that inside my mesh, the child the mesh to the empty game object. it works, but i would rather just change the center axis point of the object itself. maybe this is what i should be asking about instead? but i don't think that is possible in unity?

    Yes, i am going to component - physics - meshcollider to add the collider. i was not aware this would use the object's mesh *as* the collider, i assumed i *had* to create a low poly mesh to use as the collider. if i do not specify a low poly mesh to use as the collider, no collision occurs, hence my assumption that i have to have a low poly mesh as the collider. however, if i place two meshes with low poly colliders on top of each other, even tho the colliders are not properly aligned with the mesh, collisions occur where the colliders are in the scene (not where the meshes are). if i check "generate collider" in the fbx import option, no collisions occur. i am exporting only mesh lightmap data from my 3d app, nothing else.

    i'm afraid it has to do with the local coordinate space the center of which is somehow getting shifted way outside the object during export. i'll go back to my 3d app and recreate basic objects and see if that fixes it. when i exported, i exported the objects as a collection/hierarchy and when i did that, it seemed to change the sub-object local center coordinate space to some arbitrary center point.

    thanks for the response andeeee, i do appreciate it.
    -i.phaedrus
     
  5. dataphile

    dataphile

    Joined:
    Dec 8, 2012
    Posts:
    1
    The objects have to be aligned to the world in your 3d program.

    You have to merge the (visible) mesh objects into one, you can split them again afterwards [blender object mode, select all objects, ctrl+j]
    then set the origin of the mesh to some memorable point :
    Set the 3d cursor to the center of the screen [blender shift+c]
    Move the origin of the mesh to the 3d cursor [blender object mode, menu : Mesh : Transform : Origin to 3d cursor]
    Move the mesh to the origin [object mode, menu : Mesh : Transform : Geometry to origin]
    Your object is now centered in the world.
    No make a copy of your mesh file (for the mesh collider)
    You can then split the visible objects again into their loose parts. [blender edit mode : press 'a' until vertexes are selected, press 'p' and select option e.g. 'by loose parts']

    Open the collider copy, simplify it, remove subsurface modifier etc.
    It is aligned to the world as above, but a single object.