아래 그림 처럼 부모가 Cube 자식이 비어 있는 Sphere 트리거 인 경우
[상황 설정]
자식 오브젝트와 부모 오브젝트 각각에 BoxCollide (Trigger 가 켜진) 와 스크립트가 변로로 존재하고(OnTriggerEnter 가 각각 있는) 부모에만 Rigidbody 가 있다면
Sphere 에 충돌시 부모의 OnTriggerEnter 와 자식의 OnTriggerEnter 가 모두 불리는데
이는 자식과 부모를 하나의 닫힌 Mesh 라고 판단하기 때문
그래서 각각 부모와 자식의 스크립트의 OnTriggerEnter 가 호출되게 하려면
자식에도 Rigidbody 를 추가해줘야 한다
Trigger in child object calls OnTriggerEnter in parent object
The parent object is a small cube with a box collider trigger to fit and a kinematic rigidbody. the child of that object is an empty with a sphere collider trigger that is larger than the box collider.
different scripts are in both parent and child with OnTriggerEnter functions.
expected behavior: when the larger sphere collider (a component of the child) is triggered without triggering the parent, OnTriggerEnter is called in the child object's script.
observed behavior: when the larger sphere collider is triggered, OnTriggerEnter is called in both the parent and the child scripts.
Answer by hoy_smallfry · '13년 Mar월 04일 PM 09시 47분
Read the section labeled "Compound Colliders" on this page.
Long story short, collider shapes can't be concave and the only way to accomplish something concave is to treat all convex colliders in children under a parent as if they are one shape, if the parent is the only one with a rigidbody. So, your parent is treating it as if its a complex shape, hence OnTriggerEnter in your parent is getting called.
Try this: give the child a kinematic rigidbody. This will separate it from the parent collision, but still allow it to be moved by the parent's transform instead of physics.
However, be aware that if one touches or encompasses the other, now that they are seen as separate entities, a collision trigger will get registered between the two, even if it's just at the beginning of the scene. They won't bounce off each other since one is a trigger, but you may want to have each OnTriggerEnter function ignore the other Collider if it matches the tag of the other:
I hope that helps!
· Hide 11 · Share
buscommando · '13년 Mar월 05일 AM 02시 34분 1
I will experiment with this. Thank you much!
The parent's trigger matches the parent's mesh exactly, if something triggers it the parent dies.
The child's trigger is a spatial buffer - if something triggers the child's collider, the parent moves/runs away from the object that triggered it.
I had not considered giving both the parent and the child I$$anonymous$$ rigidbodies, currently only the parent has a rigidbody.
$$anonymous$$y solution in the interim was to remove the collider from the parent and add a second child with its own OnTriggerEnter script and a trigger collider identical to the parent's old collider. It worked but felt kludgey, your solution seems a bit more elegant.
kalibcrone buscommando · '17년 Jul월 13일 PM 01시 06분 2
Just a friendly note, "I$$anonymous$$" stands for "Inverse $$anonymous$$inematics" and doesn't really mean the same thing in this context of a $$anonymous$$inematic RigidBody. The term I$$anonymous$$ is generally used when talking about rigging a model for animation.
pas0003 · '13년 Jun월 03일 AM 10시 27분 0
Thank you so much for that tip!! :D
filip_andry · '14년 Jul월 01일 AM 06시 58분 0
Thanks, It worked for me.
einzweidrei · '15년 Feb월 24일 AM 10시 42분 1
Yes, $$anonymous$$inematic Rigidbody did it exactly. Thanks, this made it work finally after long period of banging my head around. :-)
dgreedy · '15년 Apr월 29일 PM 11시 23분 0
Buscommando's solution of seperating the triggers and trigger scripts into separate children of the parent object worked well for me. Thanks.
ref : answers.unity.com/questions/410711/trigger-in-child-object-calls-ontriggerenter-in-pa.html
'게임엔진(GameEngine) > Unity3D' 카테고리의 다른 글
머신러닝 강화학습 (ML-Agents) (0) | 2021.07.04 |
---|---|
Load prefabs via script and save scene in Unity Editor (0) | 2021.04.28 |
Vector3.Scale : Multiplies two vectors component-wise. (0) | 2021.01.13 |
Prefab Control, UnpackPrefab completely (0) | 2020.12.20 |
모바일 기기의 Tile Based Rendering(타일 기반 렌더링) (0) | 2020.02.24 |