Question by
sudipghimire · Oct 23, 2018 at 01:46 PM ·
scripting problemcollisionphysicschild object
[emergency]Know collision between child object of two object
Shortly, I simply wants to control the collision of child object from parent script
Describing my Problem..
i have 2 humanoid character and i am controlling both of them from single script in one character like GAME OBJECT!STATEMENT and so on...
When i came to collision i want to do some stuff when legs of both character are collided or either hands and i have only one option to add script to each child object and that will be so tedious so
Please Help me if you want to contact me my email-id is sudipghimire533@gmail.com
Comment
Answer by UnityCoach · Oct 23, 2018 at 02:18 PM
Ok, so you want to catch the collision between two objects of a same hierarchy, from the root?
Hum. 1st, you're going to receive the collision message twice. You need to filter this. If you catch the message up the hierarchy, the only way to know the object down the hierarchy that hit another is through the contact points.
OnCollisionEnter (Collision col)
{
GameObject thisColliderObject = col.contacts[0].thisCollider.gameObject;
if (thisColliderObject.GetInstanceID() > col.gameObject.GetInstanceID())
return;
}