I am trying to create randomly generated path properly? Think of flappy bird (its not really) but my code/algorithm is all wrong. If I make BarMax, BarMin too large, then player can cheat cos in centre there will always be space. Make it too small and pipes are spawned randomly and sometimes very close to each other (unlike flappy). So my player sometimes could run into a situation where its impossible to move past two pipes. My adjacent pipes are really close together as well unlike flappy birds big gap between pipes.
So this is what i dont want to happen. I have also thought about spawning sets of pre-configured pipes but then i thought they might run into this impossible situation at some point too. I had my level set-up like this So when a bar touches the looper, it spawns again - code is above.
int numBGPanels = 35;
float BarsMax = 1.5f; float BarsMin = -1.5f;
float widthOfBGObject = 1; float offset = 0.75f; Vector3 pos;
void Start() {
StartBarsPosition(); }
void OnTriggerEnter2D(Collider2D collider) {
if(collider.tag == "Bars") { // this is not getting called cos theres no collider attached atm
pos = collider.transform.position;
pos.x += widthOfBGObject * numBGPanels * offset;
pos.y = Random.Range(BarsMin, BarsMax);
collider.transform.position = pos;
}
}
void StartBarsPosition() {
GameObject[] bars = GameObject.FindGameObjectsWithTag("Bars");
foreach(GameObject bar in bars) {
Vector3 initialpos = bar.transform.position;
initialpos.y = Random.Range(BarsMin, BarsMax);
bar.transform.position = initialpos;
}
}