Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // calculating orbit forces
- foreach(GameObject body1 in bodies)
- {
- foreach (GameObject body2 in bodies) {
- if (body1.transform.position != body2.transform.position)
- {
- float m1 = body1.GetComponent<Rigidbody2D>().mass;
- float m2 = body2.GetComponent<Rigidbody2D>().mass;
- decimal g = (decimal)6.674 * (decimal)Mathf.Pow(10, -11);
- float distance = Vector2.Distance(body1.transform.position, body2.transform.position) / 3000;
- Vector2 direction = body2.transform.position - body1.transform.position;
- direction.Normalize();
- decimal force = g * (decimal)((m1 * m2) / Mathf.Pow(distance, 2));
- body1.GetComponent<Rigidbody2D>().AddForce(direction * (float)force);
- }
- }
- body1.GetComponent<Body>().Calculate();
- }
- // calculating energy
- float velSquared = GetComponent<Rigidbody2D>().velocity.sqrMagnitude;
- float mu = (float)g * (GetComponent<Rigidbody2D>().mass + centre.GetComponent<Rigidbody2D>().mass);
- float distance = Vector2.Distance(transform.GetComponent<Rigidbody2D>().position, centre.GetComponent<Rigidbody2D>().position) / 3000;
- float energy = (velSquared / 2) - ((mu) / distance);
- Debug.Log(energy);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement