Player walks through imported model

I checked the answers on this thread, but unfortunately, none of them has worked. Even after adding Component/Mesh/Mesh Renderer and Component/Physics/Mesh Collider to the model in the hierarchy, the player can still walk through its walls.

I have also used the mesh collider under the model’s prefab in the Project window and dragged the prefab’s mesh collider onto the model’s instance in the Hierarchy window. Once I do this, the player can no longer walk through the model’s walls, indicating that the model’s colliders have been generated.

The problem with this approach is that when the I open the model’s doors via animation, the door’s collider doesn’t move, which prevents the player from entering into what looks like an open door.

So, I’m thinking that using the prefab’s mesh collider is having some side-effect I don’t understand. Is there some other, better way to created colliders for the model that will move with, say, the animated door? Thanks in advance.

Have you tried to set your rigidbody to Is Kinematic = true ? Otherwise please paste your setup..

–

4 Answers

4

In the inspector select your mesh, then select the door which will be the child of your mesh, if they are, delete only door’s mesh collider component. Now you are free to pass through the door.

Well, I want the door's collider to be there. When the door is closed, after all, the player shouldn't be able to pass through it. I just want the collider to move with the door when it opens. So, I'm not sure how deleting the door's collider would help. Also, I don't think I can do that. The collider is assigned to the model's mesh, not the door's. That's precisely the problem. I don't know how to assign a collider to just one part of the mesh (e.g. the door) without assigning it to the entire mesh (i.e. the model).

–

- Create a box collider. - Make it a child for the door - Adjust the size of box collider same as door using scale - Remove mesh renderer component from the box collider Now you have a bare bone box collider for your door and it swings with it.

–

What kind of animatiin are you using? Keyframes in Unity or exported bone based animation? In both cases it should be possible to attach a collider component to the moving element, in the worst case by parenting an Empty to the door. Vertex based animations are a diiferent matter, though (but I don’t even know if Unity can import those…).

I'm using keyframe animation (no bones) from Daz 3D. I don't know if Daz 3D animates via vertex animation. Actually, I'm not sure I understand what vertex animation is.

–

Vertex Animations are animations based on morph targets. You have multiple, slightly different versions of a model and one master model. The master model can be morphed to look like any of the target models and animated between the different states. Is used mainly for face animations.

–

OK, thanks Piflik. I guess I don't know then what Daz uses.

–

Well...you should be able to figure out the important bit in Unity: If you look at your mesh in Unities Project Tab, is ist a little hierarchy with sub meshes (Door, Door Frame, handle or bone objects), or is it just one single mesh? In the first case, you should be able to identify the object/bone that represents the door and any component you add to this object/bone will follow its animation. Put a collider there and you should be able to walk through the door, when it's open, but not, when it's close.

–

Sorry for the delay. I can only work on this after my paying job. As to your question, yes, the problem is that the mesh itself is one. There are no sub meshes. If I understand you correctly, I need to figure out how to create sub meshes, is that right?

–

So in Unity3D you have to have colliders for objects to appear as solid.
Colliders do basically as said in the name itself.
The detect collisions. Colliders inherit the fact that they aren’t able to be passed through unless, in the inspector you check the box for ‘is trigger’ but usually you won’t have to use that unless you actually know what you are using it for. Documentation for colliders are found here: http://docs.unity3d.com/Documentation/ScriptReference/Collider.html
But they can be a little vague in the explaining portion or kind of hard to explain.
So in Unity if you create a box from the Create Object → Box you see if you click on the box it has the ‘Box Collider’ on it. Colliders don’t allow other colliders to pass through them. So your player, having a ‘Capsule Collider’ cannot pass through the actual box itself.

  • When you import a model (from say
    Blender, 3DS Max, Sketchup, Maya
    etc.) you export a mesh. The mesh is
    the actual object in which has a
    ‘Mesh Renderer’ on it. So if you
    double click in the scene view the
    object that you have imported and
    then goto the menus then under
    Components -> Physics -> Box Collider while having the mesh
    selected (By double click it) it will
    add a box collider to it, you can add
    other colliders to mess around with
    but generally box colliders work for
    doors (since they are rectangular).
    So in the inspector you can adjust
    the box collider’s
    attributes/variables to what you need
    for the door. If you want to assign
    part of the collider to a part of the
    mesh you can just adjust the
    colliders itself.

" If you want to assign part of the collider to a part of the mesh you can just adjust the colliders itself." Thank you for the extended answer. I appreciate your taking the time to be so thorough. For some reason your last sentence isn't making sense to me. What do you mean by "assign part of the collider to the mesh"? When I create a new box collider, it moves all right, only without the mesh. I'm not sure how I "hook" the mesh onto it.

–

Ok so this is actually a bit of a parenting problem that you seem to be having. What I said for the last sentence was meaning the parameters on the mesh script in the inspector. It seems like you have the Box Collider added to a parent object and are moving the child object. You best bet is to add the collider to the raw mesh object (the actual mesh). -Devon

–

OK, but the raw mesh object is the entire house. I only want the door to move. Won't I just end up moving the entire house back and forth instead of just the door?

–

I just read this <a href="http://answers.unity3d.com/questions/12257/blender-colliders.html">thread</a>, which makes me think this problem is only solvable if sub meshes and therefore bones already exist. Since this model didn't come with them, I'm wondering if I'm just out of luck.

–

OK, so I’m going to “answer” this problem by declaring it unsolvable. If anyone knows I’m wrong, by all means, please post a correction.