void createDebrisSat(Vector4 passColor, GameObject sat) { clsSatellite clsSat = sat.GetComponent <clsSatellite>(); float sinTheta = Mathf.Sin(clsSat.posTheta); int randSteps = Random.Range(3, 30); Vector3 startNewPos = new Vector3( clsSat.dist * (sinTheta + (clsSat.thetaRate * angleStep * randSteps)) * Mathf.Cos(clsSat.posPhi + (clsSat.phiRate * angleStep * randSteps)), clsSat.dist * (sinTheta + (clsSat.thetaRate * angleStep * randSteps)) * Mathf.Sin(clsSat.posPhi + (clsSat.phiRate * angleStep * randSteps)), clsSat.dist * Mathf.Cos(clsSat.posTheta + (clsSat.thetaRate * angleStep * randSteps)) ); GameObject s = GameObject.Instantiate(sat, startNewPos, Quaternion.identity); s.hideFlags = HideFlags.HideInHierarchy; s.transform.localScale = new Vector3(2, 2, 2); s.GetComponent <SphereCollider>().radius /= 2; s.tag = "Debris"; clsSatellite sClsSat = s.GetComponent <clsSatellite>(); float randOffset = Random.Range(0, 3000); sClsSat.dist = earthRadius + 5 + (randOffset / 1000); int randThetaOffset = Random.Range(5, 75); int randPhiOffset = Random.Range(5, 75); sClsSat.angleRate = angleStep; sClsSat.posPhi += angleStep * 2 * randPhiOffset; sClsSat.posTheta += angleStep * randThetaOffset; s.GetComponent <Renderer>().material.color = passColor; //orange numDebris++; satMaster[currSatSet % satMaster.Count].Add(s); s.GetComponent <Rigidbody>().detectCollisions = true; }
/// <summary> /// Creates a randomly positioned and angled satellite in stable orbit. /// </summary> public void addSatGen(int satPos) { float randOffset = Random.Range(0, 2000); int randPhiRate = Random.Range(1, 3); int randThetaRate = Random.Range(1, 3); //throw in some chaotic motion int randDirection = Random.Range(0, 20); if (randDirection > 10) { randPhiRate *= -1; } if (randDirection % 2 == 0) { randThetaRate *= -1; } //chaotic starting positions float randStartPhi = Random.Range(-Mathf.PI, Mathf.PI); float randStartTheta = Random.Range(-Mathf.PI, Mathf.PI); float dist = 5.5f + (randOffset / 1000); float sinTheta = Mathf.Sin(randStartTheta); Vector3 startPos = new Vector3( dist * sinTheta * Mathf.Cos(randStartPhi), dist * sinTheta * Mathf.Sin(randStartPhi), dist * Mathf.Cos(randStartTheta)); GameObject s = GameObject.Instantiate(satPrefabs[satPos - 1], startPos, Quaternion.identity); //s.hideFlags = HideFlags.HideInHierarchy; clsSatellite c = s.GetComponent <clsSatellite>(); //distance is from center of the earth c.dist = dist; c.posPhi = randStartPhi; c.posTheta = randStartTheta; //c.posTheta = c.posPhi; c.phiRate = randPhiRate; //c.thetaRate = randThetaRate; c.thetaRate = c.phiRate * 2; c.angleRate = 0.0005f; GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>().addSat(); }
//adds a new satellite in orbit at a random position travelling in a random direction void addSat() { float randOffset = Random.Range(0, 3000); int randPhiRate = Random.Range(2, 6); int randThetaRate = Random.Range(2, 6); //throw in some chaotic motion int randDirection = Random.Range(0, 20); if (randDirection > 10) { randPhiRate *= -1; } if (randDirection % 2 == 0) { randThetaRate *= -1; } //chaotic starting positions int randStartPhi = Random.Range(1, 16364); int randStartTheta = Random.Range(1, 16384); float dist = earthRadius + 5 + (randOffset / 1000); float sinTheta = Mathf.Sin(randStartTheta); Vector3 startPos = new Vector3( dist * sinTheta * Mathf.Cos(randStartPhi), dist * sinTheta * Mathf.Sin(randStartPhi), dist * Mathf.Cos(randStartTheta)); GameObject s = GameObject.Instantiate(satPrefab, startPos, Quaternion.identity); //s.hideFlags = HideFlags.HideInHierarchy; clsSatellite c = s.GetComponent <clsSatellite>(); //distance is from center of the earth //dist = radius + minimum distance + randomvalue scaled to be between 500-700km c.dist = dist; c.posPhi = randStartPhi; c.posTheta = randStartTheta; c.phiRate = randPhiRate; c.thetaRate = randThetaRate; c.angleRate = angleStep; numSats++; satMaster[numSats % satMaster.Count].Add(s); }