我有一个预制的 NPC,它附有一个物理装置(用来做一些特定的布娃娃的东西)。我需要避免同一装备( ARM 、腿等)上的各种碰撞器相互碰撞,但它们必须能够与其他实例化 NPC 的装备发生碰撞。
有没有办法做到这一点?我知道我可以通过将所有碰撞器放在一个单独的层上来避免所有碰撞器发生碰撞,但我无法为每个 NPC 创建一个新层。
谢谢
最佳答案
如果你有的话,你可以通过在你的 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);
}
}
}
}
关于unity3d - 防止同一钻机上的对撞机相互碰撞。但允许它们与其他钻井平台发生碰撞。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31649632/