The project is simple, just two sprites and two scripts, One script rotates the objects so they face the camera. The other script is more complicated. It is an attempt to make the second sprite orbit around the first. When I play the project it looks like it quickly makes one orbit and then the unity window stops responding. I have made some console commands to check values of variables, and they seem ordinary. I have looked for the log files of unity, but I haven’t found errors in the one log file I found. I looked for the other log file, but there was no file in the folder.
This is my orbit script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Orrery2 : MonoBehaviour
{
public Transform Center;
public Transform Other;
float x;
float y;
float z;
float Begining = 1;
float Elapsed;
void FixedUpdate()
{
Elapsed = Begining++;
PositionFromDate();
Debug.Log(Elapsed);
Debug.Log("x:" + x + ", " + "y:" + y + ", " + "z:" + z);
Other.transform.position = new Vector3(x,y,z);
}
void PositionFromDate()
{
float a = 1f * Elapsed; //Semi-Major Axis
float e = 0.8f * Elapsed; //Eccentricity
float i = 1f * Elapsed; //Inclination
float W = 1f * Elapsed; //Longitude of the Ascending Node
float w = 1f; //Argument of Periapsis
float M = 1f; //Mean Anomaly
float E = 1f; //Eccentric Anomaly
//Newton's Method
E = M;
while (true)
{
float dE = (E - e * Mathf.Sin(E) - M) / (1 - e * Mathf.Cos(E));
E -= dE;
if (Mathf.Abs(dE) < 1e-3){
break;
}
}
//Determine P and Q, 2d coordinate system in plane of orbit
float P = a * (Mathf.Cos(E) - e);
float Q = a * Mathf.Sin(E) * Mathf.Sqrt(Mathf.Abs(1 - Mathf.Pow(e, 2)));
Debug.Log("Line 46 " + "a:" + a + ", " + "e:" + e + ", " + "i:" + i + "W:" + w + ", " + "w:" + w + ", " + "M:" + M + ", " + "E:" + E + ", " + "P:" + P + ", " + "Q:" + Q);
// rotate by argument of periapsis
x = Mathf.Cos(w) * P - Mathf.Sin(w) * Q;
y = Mathf.Sin(w) * P + Mathf.Cos(w) * Q;
Debug.Log("Line 52 " + "a:" + a + ", " + "e:" + e + ", " + "i:" + i + "W:" + w + ", " + "w:" + w + ", " + "M:" + M + ", " + "E:" + E + ", " + "P:" + P + ", " + "Q:" + Q);
// rotate by inclination
z = Mathf.Sin(i) * x;
x = Mathf.Cos(i) * x;
Debug.Log("Line 58 " + "a:" + a + ", " + "e:" + e + ", " + "i:" + i + "W:" + w + ", " + "w:" + w + ", " + "M:" + M + ", " + "E:" + E + ", " + "P:" + P + ", " + "Q:" + Q);
// rotate by longitude of ascending node
float xTemp = x;
x = Mathf.Cos(W) * xTemp - Mathf.Sin(W) * y;
y = Mathf.Sin(W) * xTemp + Mathf.Cos(W) * y;
Debug.Log("Line 65 " + "a:" + a + ", " + "e:" + e + ", " + "i:" + i + "W:" + w + ", " + "w:" + w + ", " + "M:" + M + ", " + "E:" + E + ", " + "P:" + P + ", " + "Q:" + Q);
}
}