stepConstrained method

void stepConstrained(
  1. double stepSize,
  2. Size bounds,
  3. double threshold,
  4. double strength,
)

Implementation

void stepConstrained(
    double stepSize, Size bounds, double threshold, double strength) {
  var up = vm.Vector2(0, -1);
  up.scale(1 / (max(0.1, bounds.height - (position.y + threshold))));
  var down = vm.Vector2(0, 1);
  down.scale(1 / (max(0.1, position.y - threshold)));
  var left = vm.Vector2(-1, 0);
  left.scale(1 / (max(0.1, bounds.width - (position.x + threshold))));
  var right = vm.Vector2(1, 0);
  right.scale(1 / (max(0.1, position.x - threshold)));

  var force = up + down + left + right;
  force.scale(strength);
  stepForce(stepSize, force);
}