原來我的場景中有一個平面Plane帶Mesh Collider碰撞器組件,一個主角Hero帶有一個Box Collider碰撞器和有重力的Rigidbody剛體組件,主角可以放在平面上。
在導入場景后,隱藏平面Plane,給一個地板添加一個Mesh Collider碰撞器,把主角放地板上,結果主角居然直接穿透過去,很奇怪。
然后我先隱藏平面Plane,再導入場景,再給一個地板添加一個Mesh Collider碰撞器,把主角放地板上,結果主角可以放在上面。
?
?
在官方文檔中看到這段話:
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),那么就可以和其他網格碰撞器碰撞。
?
所以可能是因為在導入場景后才隱藏平面Plane,使得地板的碰撞器為了不和還未隱藏的平面Plane碰撞而變的無效,導致主角和地板也沒有了碰撞。
我又做了一個試驗,把主角放在平面plane上面,然后再創建一個豎著的平面plane,結果主角可以穿透豎著的平面plane,然后我又標記了豎著的平面plane為Convex,就穿透不過去了,說明應該是這樣的。
所以我先隱藏或者刪除平面Plane再導入場景,再在場景的地板節點添加Mesh Collider碰撞器組件,就可以站在上面了。
?
?
還有一些要注意的點:
1.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),否則網格碰撞器間不會發生碰撞。因此,它們最常被用于背景對象比如環境布景。
2.Convex Mesh Colliders must be fewer than 255 triangles.
凸起的網格碰撞器含有的三角形面不能多于255個。
3.Primitive Colliders are less costly for objects under physics control.
原型控制器對于對象的物理控制更加節省資源。
4.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.
當為游戲對象附加了網格碰撞器,其網格屬性將被定義為用于渲染的網格,可以通過指派其他網格來改變。
5.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.
要給一個對象添加多個碰撞器,應該創建子對象并給每個子對象添加一個碰撞器。這使每個碰撞器可以被單獨操作。
6.You can look at the gizmos in the Scene View to see how the Collider is being calculated on your object.
可以通過場景視圖(Scene View )中的線框(gizmos)來查看碰撞器在你的對象上的預期效果。
7.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.
碰撞器盡量匹配對象的比例。如果有一組不規則伸縮(每一維度上的比例都不相同),只能使用網格碰撞器才能完全匹配。
8.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組件移動的對象的碰撞/觸發信息,你必須給移動對象附件剛體。