// Start is called before the first frame update void Start() { a = Instantiate(a); m = Instantiate(m, new Vector3(4f, 0f, 0f), Quaternion.identity); aC26 = a.GetComponent <attractorChapter2_6>(); mC26 = m.GetComponent <moverChapter2_6>(); }
public Vector3 attract(moverChapter2_6 mover) { Vector3 difference = location - mover.location; float dist = difference.magnitude; Vector3 gravityDirection = difference.normalized; float gravity = 6.7f * (mass * mover.mass) / (dist * dist); Vector3 gravityVector = (gravityDirection * gravity); return(gravityVector); }