Problems with OnCollisionEnter, rigidbodys and compound colliders

Hi there,
I have a problem with the OnCollisionEnter method. The situation is this. I have a moving truck with a rigidbody and a container with 6 box colliders attached as a child. Like you can see in the screen my truck is doing random moves on this street like braking, changing lanes, rumbling over the sidewalk and so on. Everything is done with physics so the objects inside (also rigidbodys) fly around. This works fine so far.

22538-screen.png

My problem is that I want to calculate the damage which the objects have taken during the ride. So far I use coll.relativeVelocity.magnitude for that. But this is used best in OnCollisionEnter in a script attached to the objects. This event is immediately fired by the floor so the collisions with the walls are ignored, because it is a compound collider (Except it leaves the floor, but that happens rarely). I also tried it in OnCollisionStay but then the friction with the colliders cause the most damage. Sadly I can’t make use of the collision.contacts because they haven’t something like relativeVelocity.

If I attach rigidbodys to the box colliders the truck behaves totally different and can’t even move forward.

I think my best approach was to create a CollisionListener script and attach it to the 6 box colliders. But somehow the OnCollisionEnter isn’t even fired.

public class CollisionListener : MonoBehaviour 
{
    void OnCollisionEnter(Collision coll)
    {
        Debug.Log("Here");
        if (coll.gameObject.tag != "Finish")
        {
            if (coll.relativeVelocity.magnitude > 0.9f)
            {
                coll.gameObject.GetComponent<Damage>().GiveRelativeVelocity(coll.relativeVelocity.magnitude);

            }
        }
    }

}

So is there any solution how I can handle more collisions in the OnCollisionEnter, access the single box colliders, calculate the impact velocity in a different way or something I have tried so far in a correct way :-).

I got a solution. Took me a while beacause I’m relative new to Unity. For anybody who looks it up:
You have to detach the colliders and connect them with the old parent via a fixed joint. Then the walls will have an own rigidbody but will stick with the position of the truck. Now they wont act as a compound collider and you can work with the OnCollisionEnter() of each side.

I think Layer in unity will help you in this situation. You can set the object you wanna calculate the damage to the same layer, so the OnCollisionEnter will only be called when the things in the same layer colliding with each other. Through this, you can ignore the influence from other unecessary colliders(like floor you dont want), then in OnCollisionEnter function, you can get the damage degree you want, good luck!