我有一个预制的NPC,附有一个物理装备(用来做一些特殊的布娃娃)。 我需要避免同一装备(臂,腿等)上的各种碰撞器相互碰撞,但它们必须能够与其他实例化NPC的装备发生碰撞。
有没有办法做到这一点? 我知道我可以通过将它们放在一个单独的层上来避免碰撞所有碰撞器,但我不能为每个NPC创建一个新层。
谢谢
I have a prefab NPC which has a physics rig attached to it (to do some specific rag-doll stuff with). I need to avoid the various colliders on the same rig (arms, legs etc) from colliding with each other, but they have to be able to collide with the rigs of other instantiated NPCs.
Is there a way to do this? I know I can avoid all the colliders from colliding by putting them on a separate layer, but I cant create a new layer for every NPC.
Thanks
最满意答案
你可以在你的NPC课上设置IgnoreCollision,如果有的话
http://docs.unity3d.com/ScriptReference/Physics.IgnoreCollision.html
如此简单地遍历钻机中的所有碰撞器并设置为相互忽略
void Start() { colliders = GetComponentsInChildren<Collider>(); foreach(Collider collider in colliders) { otherColliders = GetComponentsInChildren<Collider>(); foreach(Collider otherColider in otherColliders) { if (collider != otherColider) { Physics.IgnoreCollision(collider, otherColider); } } } }You can do by setting up IgnoreCollision on your NPC class if you have any
http://docs.unity3d.com/ScriptReference/Physics.IgnoreCollision.html
So simple loop through all colliders in the rig and set up to ignore each other
void Start() { colliders = GetComponentsInChildren<Collider>(); foreach(Collider collider in colliders) { otherColliders = GetComponentsInChildren<Collider>(); foreach(Collider otherColider in otherColliders) { if (collider != otherColider) { Physics.IgnoreCollision(collider, otherColider); } } } }更多推荐
发布评论