# Child Rigid Body collision problem

Hi, I’ve run across a weird problem lately which I’m unable to resolve myself.

My goal is to create multiple cars which each consists of 2 objects, front and back.

-The front and back are supposed to detect collision. (but different colliders!)

-The front isn’t suppose to be affected by physics, the back is.

-The front is also supposed to come of at a certain point, and then react normally to physics.

-The front part has to move perfectly with the back part until it comes of.

The thing is, I can’t figure out how. Solutions I’ve tried:

1. If I lock the child rigid body in local space(either with code or with the kinematic check-box), it will stop detecting collision with other child rigid bodies(other car fronts) in the scene.

2. If I remove the rigid body component but still lock the child into place, collision will look normal, but collision will not be detected.

3. If I make the front object a child with a rigid body, but without the lock, it will work properly, but obviously react separately to physics when compared to the parent.

Edit:

1. Two colliders with a rigid body as parent doesn’t work either, unless there is some way to differentiate between colliders by code, as both colliders send their data to the parent rigid body(whilst I aim to to have different effects on the back and front).

2. Two rigid bodies attached by a Fixed Joint almost does the trick, except that joints allow for some degree of movement between the bodies. Also joints require two non kinematic rigid bodies…which means the front will always be affected by physics…

I’m not sure what to do at this point… I’m thinking its not possible actually, as it would probably require collision of two kinematic rigid bodies…

Any tips or suggestions for alternative routes to the same result would be greatly appreciated!

Add en empty game object and put all of your colliders as children. Now put the rigidbody on the parent object (the empty one you created).

When you want to separate them, just unparent the object:

``````transform.parent = null;
``````

and it will go on its own.

(been a few months and you probably have this solved/found other methods, but for any who have a similar question and see this: )

This code will give the desired functionality of detecting child colliders:

``````void OnCollisionEnter(Collision other){
ContactPoint contact = other.contacts[0];
print(gameObject.name +" got collided from contact " + contact.otherCollider);
}
``````

collision(unfortunately means it won’t work with triggers) contains a contacts variable:

you can then retrieve the first contact( contacts[0] ), and check the ‘otherCollider’ variable it contains, to get the specific collider that made contact(in this case, the child object’s collider).