// Use this for initialization void Start() { fileName = this.gameObject.name + ".txt"; if (!File.Exists(fileName)) { FileWriter = File.CreateText(fileName); FileWriter.AutoFlush = true; FileWriter.WriteLine("RelativeTo\tRelativePos\tX\tY\tZ\tRelativeVel\tApoapsisHeight\tPeriapsisHeight\tCurrentDistance\tStartTheta\tStartPhi\tcurrentTheta\tcurrentPhi\tmaxDistanceAngleTheta\tmaxDistanceAnglePhi\tminDistanceAngleTheta\tminDistanceAnglePhi\tperiod\tspin\tlastPos\tlastPhi\tperiodSum"); } else { FileWriter = File.AppendText(fileName); FileWriter.AutoFlush = true; } RelativePos = RelativeTo.gameObject.transform.position - this.transform.position; RelativePos /= (PlanetData.AE / PlanetData.distanceUmrechnung); RelativeVel = RelativeTo.GetComponent <Rigidbody>().velocity - this.GetComponent <Rigidbody>().velocity; StartTheta = Mathf.Asin(RelativePos.y / RelativePos.magnitude); StartPhi = Mathf.Atan2(RelativePos.z, RelativePos.x); ApoapsisHeight = RelativePos.magnitude; MaxDistanceAngleTheta = StartTheta; MaxDistanceAnglePhi = StartPhi; PeriapsisHeight = RelativePos.magnitude; MinDistanceAngleTheta = StartTheta; MinDistanceAngleTheta = StartPhi; }
// Update is called once per frame void FixedUpdate() { //RelativePos = RelativeTo.gameObject.transform.position - this.transform.position; //RelativePos = RelativePos * PlanetData.distanceUmrechnung / PlanetData.AE; RelativePos = (this.transform.position - RelativeTo.gameObject.transform.position) * PlanetData.distanceUmrechnung / PlanetData.AE; RelativeVel = RelativeTo.GetComponent <Rigidbody>().velocity - this.GetComponent <Rigidbody>().velocity; CurrentDistance = RelativePos.magnitude; CurrentTheta = Mathf.Asin(RelativePos.y / RelativePos.magnitude); CurrentPhi = Mathf.Atan2(RelativePos.z, RelativePos.x); if (RelativePos.magnitude > ApoapsisHeight) { ApoapsisHeight = RelativePos.magnitude; MaxDistanceAngleTheta = CurrentTheta; MaxDistanceAnglePhi = CurrentPhi; } else if (RelativePos.magnitude < PeriapsisHeight) { PeriapsisHeight = RelativePos.magnitude; MinDistanceAngleTheta = CurrentTheta; MinDistanceAnglePhi = CurrentPhi; } PeriodSum += Time.deltaTime; if (LastPhi > CurrentPhi) { Period = PeriodSum; PeriodSum = 0; } LastPhi = CurrentPhi; Tagecounter += tickDays; }