static void NewtonUpdate(NBodyObject body) { acceleration = Vector2.zero; foreach(NBodyObject otherBody in bodies) { if(body == otherBody) continue; direction = (otherBody._transform.position - body._transform.position); acceleration += self.g * (direction.normalized * otherBody.simMass) / direction.sqrMagnitude; } body.velocity += acceleration * fixedDeltaTime; Vector2 position = body.transform.position; body.transform.position = position + (body.velocity * fixedDeltaTime); }
static void NewtonUpdate(NBodyObject body) { acceleration = Vector2.zero; foreach (NBodyObject otherBody in bodies) { if (body == otherBody) { continue; } direction = (otherBody._transform.position - body._transform.position); acceleration += self.g * (direction.normalized * otherBody.simMass) / direction.sqrMagnitude; } body.velocity += acceleration * fixedDeltaTime; Vector2 position = body.transform.position; body.transform.position = position + (body.velocity * fixedDeltaTime); }