Пример #1
0
		/// <summary>
		/// When first time called this method makes orbit clockwise, next time - oposite
		/// Orbit plane will be unchanged.
		/// </summary>
		public void MakeOrbitCircle() {
			if (attractor) {
#if UNITY_EDITOR
				if (!Application.isPlaying) {
					FindReferences();
					attractor.FindReferences();
					Undo.RecordObject(this, "Round orbit");
				}
#endif
				var v = CelestialBodyUtils.CalcCircleOrbitVelocity(
					attractor._position,
					_position,
					attractor.mass,
					mass,
					orbitData.orbitNormal,
					simControlRef.gravitationalConstant
				);
				if (relativeVelocity == v) {
					relativeVelocity = -v;
				} else {
					relativeVelocity = v;
				}
				orbitData.isDirty = true;
			}
#if UNITY_EDITOR
 else {
				Debug.Log("SpaceGravity2D: Can't round orbit. " + name + " has no attractor");
			}
#endif
		}
Пример #2
0
		/// <summary>
		/// Set the appropriate velocity for a circular orbit around current attractor. Call multiple times to change clockwise direction.
		/// </summary>
		public void MakeOrbitCircle() {
			if (Attractor) {
				if (!Application.isPlaying) {
					FindReferences();
					Attractor.FindReferences();
				}
				else {
					TerminateRailMotion();
				}
				var distanceVector = (Vector2)( _transform.position - Attractor._transform.position );
				if (distanceVector.sqrMagnitude < _simulationControl.MinAttractionRange * _simulationControl.MinAttractionRange) {
					Debug.Log("SpaceGravity2D: " + name + " is too close to attractor");
					return;
				}
				var dist = distanceVector.magnitude;
				var v = Mathf.Sqrt(Attractor.MG / dist);
				distanceVector = distanceVector / dist;
				var circVelo = new Vector2(-distanceVector.y * v, distanceVector.x * v);
				if (RelativeVelocity == circVelo) {
					RelativeVelocity = new Vector2(distanceVector.y * v, -distanceVector.x * v);
				}
				else {
					RelativeVelocity = circVelo;
				}
			}
			else {
				if (!Application.isPlaying) {
					Debug.Log("SpaceGravity2D: " + name + " has no attractor");
				}
			}
		}
Пример #3
0
        void Update()
        {
            if (UseAutoROI)
            {
                if (_body && _body.Attractor && !double.IsNaN(_body.SemiMajorAxys))
                {
                    _body.Attractor.FindReferences();
                    _body.FindReferences();
                    TriggerRadius = (float)_body.SemiMajorAxys * Mathf.Pow(_body.Mass / _body.Attractor.Mass, 2f / 5f);
                }
            }
            float parentScale = 1f;
            float scale       = 1f;

            if (IgnoreTransformsScale)
            {
                parentScale = transform.parent == null ? 1 : (transform.parent.localScale.x + transform.parent.localScale.y) / 2f;
                scale       = (transform.localScale.x + transform.localScale.y) / 2f;
            }
            _detector.radius = TriggerRadius / scale / parentScale;
        }
Пример #4
0
        void Update()
        {
            if (useAutoROI)
            {
                if (body && body.attractor && !double.IsNaN(body.orbitData.semiMajorAxis))
                {
                    body.attractor.FindReferences();
                    body.FindReferences();
                    triggerRadius = (float)body.orbitData.semiMajorAxis * Mathf.Pow((float)(body.mass / body.attractor.mass), 2f / 5f);
                }
            }
            float parentScale = 1f;
            float scale       = 1f;

            if (ignoreTransformsScale)
            {
                parentScale = transform.parent == null ? 1 : (transform.parent.localScale.x + transform.parent.localScale.y) / 2f;
                scale       = (transform.localScale.x + transform.localScale.y) / 2f;
            }
            detector.radius = triggerRadius / scale / parentScale;
        }
        private void Update()
        {
            if (UseAutoROI)
            {
                if (Target && Target.AttractorRef && !double.IsNaN(Target.OrbitData.SemiMajorAxis))
                {
                    Target.AttractorRef.FindReferences();
                    Target.FindReferences();
                    TriggerRadius = (float)Target.OrbitData.SemiMajorAxis * Mathf.Pow((float)(Target.Mass / Target.AttractorRef.Mass), 2f / 5f);
                }
            }

            float parentScale = 1f;
            float scale       = 1f;

            if (IgnoreTransformsScale)
            {
                parentScale = transform.parent == null ? 1 : (transform.parent.localScale.x + transform.parent.localScale.y) / 2f;
                scale       = (transform.localScale.x + transform.localScale.y) / 2f;
            }
            Detector.radius = TriggerRadius / scale / parentScale;
        }