public void LaunchSpaceCraft(float speed, float direction, string name) { if (SpaceCraft.spaceCraftList.Count < maxSpaceCraft) { spaceCraft = GameObject.Instantiate(Resources.Load("Prefabs/MissileHead")) as GameObject; spaceCraft.name = name; spaceCraft.tag = "SpaceCraft"; spaceCraft.transform.Find("MissileMesh").name = "Mesh" + spaceCraft.name; spaceCraft.transform.Find("BB").name = "BB" + spaceCraft.name; spaceCraft.transform.parent = transform; velocity = POEarth.ParametricVelocity(); //print(velocity.magnitude*Scales.velmu2kms); velocity += speed * (Quaternion.Euler(0, direction, 0) * velocity).normalized; spaceCraft.GetComponent <SpaceCraftOrbit> ().Initialize(earth.transform.position, velocity, direction); SpaceCraft sc = spaceCraft.GetComponent <SpaceCraft> (); if (name == "Generic") { spaceCraft.AddComponent <SpaceCraftInfo> (); sc.minVelForCourseCorrection = 0; sc.maxVelForCourseCorrection = 16.3f * Scales.kms2velmu; sc.allowableNumberOfThrusts = int.MaxValue; } else if (name == "Viking") { spaceCraft.AddComponent <VikingInfo> (); sc.minVelForCourseCorrection = 0f; sc.maxVelForCourseCorrection = 2.5f * Scales.kms2velmu; sc.allowableNumberOfThrusts = 1; } else if (name == "Magellan") { spaceCraft.AddComponent <SpaceCraftInfo> (); sc.minVelForCourseCorrection = 0; sc.maxVelForCourseCorrection = 2.5f * Scales.kms2velmu; sc.allowableNumberOfThrusts = 1; } else if (name == "Galileo") { spaceCraft.AddComponent <SpaceCraftInfo> (); sc.minVelForCourseCorrection = 0; sc.maxVelForCourseCorrection = 5f * Scales.kms2velmu; sc.allowableNumberOfThrusts = 1; } } else { GUIClass.messageQueue.Enqueue(numOfSpaceCraftsMessage); } }
void Update() { line.enabled = isActive; foreach (GameObject go in spaceCraftHelper) { go.SetActive(isActive); } foreach (GameObject go in planetHelper) { go.SetActive(isActive); } if (line.enabled) { float t = 0; float deltaTime = Mathf.Floor(POPlanet.Par [1] / 90); Vector3 velocity = poEarth.ParametricVelocity(); velocity += Speed * (Quaternion.Euler(0, Direction, 0) * velocity).normalized; initialVel2.Set(velocity.x, velocity.z); initialPos2.Set(earth.transform.position.x, earth.transform.position.z); for (int i = 0; i < lineRendererLength; i++) { t += deltaTime; line.SetPosition(i, new Vector3(initialPos2.x, 0, initialPos2.y)); Integrator.AdaptiveLeapfrog(ref initialPos2, ref initialVel2, 1f, deltaTime); for (int j = 0; j < numOfHelpers; j++) { if (t == 6f * (j + 1) * deltaTime) { spaceCraftHelper [j].transform.position = new Vector3(initialPos2.x, 0, initialPos2.y); } } for (int j = 0; j < numOfHelpers; j++) { if (t == 6f * (j + 1) * deltaTime) { planetHelper [j].transform.position = poPlanet.GetPositionAfterTime(t); } } } } }