hex-world
    Preparing search index...

    Function hasLineOfSight

    • Returns true if there is an unobstructed line of sight from from to to.

      Traces the hex line between the two cells and checks whether any intermediate cell's terrain elevation pokes above the straight sight line. Both observer and target are assumed to have their eyes at eyeHeight world units above the terrain surface.

      Uses the shared ELEVATION_SCALE by default — pass elevationScale if your terrain geometry uses a custom elevationScale so LOS matches the visuals.

      Parameters

      • from: HexCoord
      • to: HexCoord
      • map: {
            getElevation(col: number, row: number): number;
            width: number;
            height: number;
        }
      • eyeHeight: number = 1.5

        Observer/target eye height above terrain, in world units. Default 1.5.

      • elevationScale: number = ELEVATION_SCALE

        World units per elevation step. Default ELEVATION_SCALE (0.5).

      Returns boolean

      const canSee = hasLineOfSight(
      offsetToHex(unitCol, unitRow),
      offsetToHex(targetCol, targetRow),
      map,
      );