//Code for Orbiting around Sun void orbit() { angle += Time.deltaTime * speed; a += Time.deltaTime * 0.5f; Quaternions.Quat q = new Quaternions.Quat(angle, new Vector3(0, 1, 0)); Vector3 p = new Vector3(one, two, three); Quaternions.Quat K = new Quaternions.Quat(1.0f, p); Quaternions.Quat newK = q * K * q.Inverse(); Vector3 newP = newK.getAxis(); transform.position = newP; }
void rotatemoon() { angle += Time.deltaTime * speed; planetPos = planet.transform.position; Quaternions.Quat q = new Quaternions.Quat(angle, new Vector3(0, 1, 0)); Vector3 p = new Vector3(one, two, three); Quaternions.Quat K = new Quaternions.Quat(1.0f, p); Quaternions.Quat newK = q * K * q.Inverse(); Vector3 newP = newK.getAxis(); transform.position = newP + planetPos; }
//Rotation of the moon void rotatemoon() { angle += Time.deltaTime * speed; //Saves location of planet in a vector 3 Vector3 planetPos = planet.transform.position; Quaternions.Quat q = new Quaternions.Quat(angle, new Vector3(0, 1, 0)); Vector3 p = new Vector3(one, two, three); Quaternions.Quat K = new Quaternions.Quat(1.0f, p); Quaternions.Quat newK = q * K * q.Inverse(); Vector3 newP = newK.getAxis(); //Sets the location for the orbit to the planet thats chosen transform.position = newP + planetPos; }