addOrbitalForce method

void addOrbitalForce(
  1. String name,
  2. Vector2 center,
  3. double strength
)

Add orbital force around a center point

Implementation

void addOrbitalForce(String name, Vector2 center, double strength) {
  final toCenter = center - position;
  final distance = toCenter.length;

  if (distance > 0) {
    // Centripetal force
    final forceDirection = toCenter.normalized();
    final force = forceDirection * (strength / (distance * distance));
    addForce(name, force);
  }
}