# Generating hidden box collider between two game objects in unity

I'm trying to implement flappy bird clone using unity. I'm creating two obstacles at random y position. I would like to create a hidden box collider game object between them, but I'm struggling with the math. I want the box collider to be generated between both game objects so that I use it to detect if the bird has passed the two obstacles.

Here is how I generate the obstacles

// function called by InvokeRepeating function

void CreateObstacle(){
// generating random upper pipe position
float randomPos = 4f-(4f-0.8f-pipeHole)*Random.value;
// adding upper pipe to stage
GameObject upperPipe = (GameObject)Instantiate(pipeObject);
// setting upper pipe position
upperPipe.transform.position = new Vector2(4f,randomPos);
// adding lower pipe to stage
GameObject lowerPipe = (GameObject)Instantiate(pipeObject);
// setting lower pipe position
lowerPipe.transform.position = new Vector2(4f,randomPos-pipeHole-4.8f);
}

• What do you mean by "hidden" box collider? – Pip Jul 2 '15 at 12:42
• a game object that is not seen, its just acting as a box collider – user3023213 Jul 2 '15 at 12:43
• Make a prefab that holds your empty gameobject + collider (+ a script probably). Middle position will be (upperPipe.transform.position + lowerPipe.transform.postion) / 2 . Then scale your trigger object based on the difference in position: (upperPipe.transform.position - lowerPipe.transform.postion). – MistaGiggles Jul 2 '15 at 12:57
• scale it in which axis ? – user3023213 Jul 2 '15 at 12:59
• Depends on which axis your pipes are aligned on. The difference in position will have a value of 0 for each axis that are aligned, you won't want to scale these. Scale it on each axis that has a difference != 0 (for example, try scale += difference/2 , and if you are using default scaling for everything the math might just work in your favor) – MistaGiggles Jul 2 '15 at 15:21