keepDistance method

bool keepDistance(
  1. GameComponent target,
  2. double minDistance
)

Implementation

bool keepDistance(GameComponent target, double minDistance) {
  if (!isVisible) return true;
  double distance = rectCollision.centerVector2.distanceTo(
    target.rectCollision.centerVector2,
  );

  if (distance < minDistance) {
    var angle = getAngleFromTarget(target);
    moveFromAngle(angle + pi);
    return false;
  }
  return true;
}