angleTo method

double angleTo(
  1. Vector2 target
)

Returns the angle formed by component's orientation vector and a vector starting at component's absolute position and ending at target. This angle is measured in clockwise direction. target should be in absolute/world coordinate system.

Uses nativeAngle to decide the orientation direction of the component. See lookAt to make the component instantly rotate towards target.

Note: If target coincides with the current component, then it is treated as being north.

Implementation

double angleTo(Vector2 target) {
  return math.atan2(
        target.x - absolutePosition.x,
        absolutePosition.y - target.y,
      ) -
      (nativeAngle + absoluteAngle);
}