moveFromAngle method

void moveFromAngle(
  1. double speed,
  2. double angle, {
  3. VoidCallback? onCollision,
})

Move Player to direction by radAngle

Implementation

void moveFromAngle(double speed, double angle, {VoidCallback? onCollision}) {
  double nextX = (speed * dtUpdate) * cos(angle);
  double nextY = (speed * dtUpdate) * sin(angle);
  Offset nextPoint = Offset(nextX, nextY);

  Offset diffBase = Offset(
        position.rect.center.dx + nextPoint.dx,
        position.rect.center.dy + nextPoint.dy,
      ) -
      position.rect.center;

  Offset newDiffBase = diffBase;

  Vector2Rect newPosition = position.shift(newDiffBase);

  if (_isCollision(newPosition.position)) {
    onCollision?.call();
    return;
  }

  isIdle = false;
  position = newPosition;
}