防止同一装备上的碰撞器相互碰撞。(Preventing colliders on the same rig from colliding with each other. But allowing t

系统教程 行业动态 更新时间:2024-06-14 16:58:30
防止同一装备上的碰撞器相互碰撞。(Preventing colliders on the same rig from colliding with each other. But allowing them to collide with other rigs.)

我有一个预制的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); } } } }

更多推荐

本文发布于:2023-04-15 03:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/c3809cd7ef2c2279b39486431e4aecd7.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:装备   colliders   Preventing   rig   rigs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!