- Home /
Flight Path Generator Troubles
This is more about getting a vote of confidence than an actual problem, I have, but it is still something I need addressed. In this project, I have made a flight path for a flying AI that uses a series of randomly picked waypoint from an array. To give more of a scattered look when multiple entities are flying at once. Right now, I'm just testing to see that I can successfully slot a random waypoint into a flight path without repeating any waypoints, and to the closest extent without calling a total success, it works. There's just one thing that bugs me.
public Transform[] TravelLocations; bool isSeed;
void Start()
{
List<int> seeds = new List<int>();
for(int i = 0; i <= TravelLocations.Length - 1; i++)
{
isSeed = false;
int seed = Random.Range(0, this.gameObject.transform.childCount - 1);
isSeed = seeds.Contains(seed);
while(isSeed == true)
{
seed = Random.Range(0, this.gameObject.transform.childCount - 1);
isSeed = seeds.Contains(seed);
}
seeds.Add(seed);
TravelLocations[i] = this.gameObject.transform.GetChild(seed);
}
}
This code actually works, but only when the first for loop is scripted to stop one short of the actual array size, i. e. (i < TravelLocations.Length - 1) If I try to fill the whole array, I can't even start the game scene from the editor. I'm worried that I've somehow made an infinite loop without realizing it, but at the same time, I'm just confused. If it works trying to fill all but one of the array's indices, what's stopping from filling that last one?
Thank you very much.