为什么带网格(mesh)的模型添加了刚体Rigidbody和MeshCollider,还是会从地板穿过去?
两个Gameobject 放置在空中, 一个是Cube,一个是茄子模型
Cube的Collider 是Box Collider , 茄汁的Collider 是mesh collider, 他们都添加了刚体(RigidBody)组件, 勾选了重力Gravity
但是, 运行的结果是:
正方块Cube下落, 掉到地面上停了下来
茄子下落,没有停下来, 穿透了地面,一直往下掉。
百事不得其解。。。
终于还是在官方文档中看到这段话:
There are some limitations when using the Mesh Collider. Usually, two Mesh Colliders cannot collide with each other. All Mesh Colliders can collide with any primitive Collider. If your mesh is marked as Convex, then it can collide with other Mesh Colliders.
使用网格碰撞器有一些限制条件。通常,两个网格碰撞器之间不会发生碰撞。所有的网格碰撞器可以和任何原型碰撞器碰撞。如果网格标记为凸起的(Convex),那么就可以和其他网格碰撞器碰撞。
试了一下, 把茄子Mesh Collider的Convex 勾上,
OK了, 停下来了!
还有一下注意事项:
http://www.ceeger.com/Components/class-MeshCollider.html
Hints 提示
- Mesh Colliders cannot collide with each other unless they are marked as Convex. Therefore, they are most useful for background objects like environment geometry.
除非被标记为凸起的(Convex),否则网格碰撞器间不会发生碰撞。因此,它们最常被用于背景对象比如环境布景。 - Convex Mesh Colliders must be fewer than 255 triangles.
凸起的网格碰撞器含有的三角形面不能多于255个。 - Primitive Colliders are less costly for objects under physics control.
原型控制器对于对象的物理控制更加节省资源。 - When you attach a Mesh Collider to a GameObject, its Mesh property will default to the mesh being rendered. You can change that by assigning a different Mesh.
当为游戏对象附加了网格碰撞器,其网格属性将被定义为用于渲染的网格,可以通过指派其他网格来改变。 - To add multiple Colliders for an object, create child GameObjects and attach a Collider to each one. This allows each Collider to be manipulated independently.
要给一个对象添加多个碰撞器,应该创建子对象并给每个子对象添加一个碰撞器。这使每个碰撞器可以被单独操作。 - You can look at the gizmos in the Scene View to see how the Collider is being calculated on your object.
可以通过场景视图(Scene View )中的线框(gizmos)来查看碰撞器在你的对象上的预期效果。 - Colliders do their best to match the scale of an object. If you have a non-uniform scale (a scale which is different in each direction), only the Mesh Collider can match completely.
碰撞器尽量匹配对象的比例。如果有一组不规则伸缩(每一维度上的比例都不相同),只能使用网格碰撞器才能完全匹配。 - If you are moving an object through its Transform component but you want to receive Collision/Trigger messages, you must attach a Rigidbody to the object that is moving.
如果你想接收通过Transform组件移动的对象的碰撞/触发信息,你必须给移动对象附件刚体。