// Use this for initialization void Start() { myRB = GetComponent <Rigidbody>(); myRB.useGravity = false; if (GameManager.instance.currentSystem != null) { subcribedTo = GameManager.instance.currentSystem.GetComponent <SystemGravity>(); subcribedTo.Subscribe(myRB); } InvokeRepeating("Grav", 0f, 0.5f); }
// Update is called once per frame private void Grav() { if (subcribedTo == null) { if (GameManager.instance.currentSystem != null) { subcribedTo = GameManager.instance.currentSystem.GetComponent <SystemGravity>(); subcribedTo.Subscribe(myRB); } return; } subcribedTo.Attract(myRB); }
// Use this for initialization void Start() { orbit = orbitObj.GetComponent <Rigidbody>(); myRb = GetComponent <Rigidbody>(); //GetComponent<UseSystemGravity>().enabled = false; theSystem = GameObject.FindGameObjectWithTag("System").GetComponent <SystemGravity>(); //theSystem.Unsubscribe(myRb); G = theSystem.G; Vector3 diff = (transform.position - orbit.position); float R = diff.magnitude; print("R " + R); speed = Mathf.Sqrt((theSystem.G * orbit.mass) / R); print("speed " + speed); transform.LookAt(orbit.transform); myRb.velocity = (transform.right * speed); }