# Unable to control trigger events for car animation collsion control

I have different car animation running on the road which have imported from max. I want to make such an intelligent System that if car start to trigger from another car it become stop. So far I have tried this.

1. Added four collider (as you can see in Fig 1) with tag name car, carBack, carLeft, CarRight

2. car left/right contains this code. Added this script to car left,right collider that if this collider hit with car object then car become stop.(And on trigger exit it resume)

 void OnTriggerEnter(Collider c)
{
if (c.tag == "Car")
{
Debug.Log("collided with : carsideTriggerScript :" + c.transform + " - object Name to stop : " + gameObject.name);
c.transform.gameObject.GetComponent<AnimationControlSpeed>().Speed = 0;
}
}

void OnTriggerExit(Collider c)
{
if (c.tag == "Car")
{
Debug.Log("Exi collided with :  carsideTriggerScript:" + c.transform + " - object Name to resume : " + gameObject.name);
c.transform.gameObject.GetComponent<AnimationControlSpeed>().Speed = 1;
}
}

3. Added script which check that if car start to collide with carBack collider then stop (And on trigger exit it resume. Same script as above).

But a scenario is creating which you can see in fig 2.

I am enable to handle it. it seems that one car collider hitting carRightCollider and same thing happen with another car so that both car become stop and unable to move again. How can i control it? as same scripts are attached to every gameobject with same OntriggerEnter and logic.

• Are all the colliders on seperate GameObjects? – hobnob Jun 23 '16 at 10:55
• each car have a own colliders – Muhammad Faizan Khan Jun 23 '16 at 11:05
• But for each car are there child game objects that hold the separate colliders. For example, does Car1 have 4 child game objects (Left, Right, Top, Bottom) colliders? If not, it might be worth separating them out into game objects. That way you can add your script to just the left/right collider child objects – hobnob Jun 23 '16 at 11:12
• yes car collider on parent object then its first child contains bottom collider then its child contains righ collider and its sibling left collider. – Muhammad Faizan Khan Jun 23 '16 at 11:27
• you mean that if i didn't added script to child collider then it will also affect the parent script who also have collider? – Muhammad Faizan Khan Jun 23 '16 at 11:28