Baltor Get started

Gallery / Godot components

Hex grid math on axial coordinates

In your harnessGodot componentMIT

Compute hex grid distance, neighbors, rings, spirals, lines, rotations, pixel conversion for pointy-top and flat-top layouts, reachable areas and A* paths, all as static functions on Vector2i axial coordinates.

Files, names only

  • ATTRIBUTION.md
  • LICENSE
  • README.md
  • baltor_test.gd
  • component.json
  • hex_grid_math.gd
  • inspect_gdscript.py
  • run_tests.gd
  • test_package.py
  • tests/test_hex_grid_math.gd
  • verification/native.json

Full files in your harness.

What it takes and gives

Class
BaltorHexGrid, extends RefCounted
Methods
axial_to_cube(hex: Vector2i) -> Vector3i; cube_to_axial(cube: Vector3i) -> Vector2i; cube_round(cube: Vector3) -> Vector3i; distance(a: Vector2i, b: Vector2i) -> int; neighbor(hex: Vector2i, direction: int) -> Vector2i; neighbors(hex: Vector2i) -> Array[Vector2i]; ring(center: Vector2i, radius: int) -> Array[Vector2i]; spiral(center: Vector2i, radius: int) -> Array[Vector2i]; and 7 more
Placement
res://baltor/godot_components/hex_grid_math/

Limits. Axial and cube coordinates only (offset coordinates must be converted by the caller). Paths assume every step costs 1; use a weighted search for terrain costs. find_path stops after max_expanded expanded hexes and returns an empty array, so an unbounded passable area needs a bound in is_passable. Pixel conversion has no origin offset or non-uniform scale. Verified with Godot 4.7.2 headless; written against the Godot 4.3 API.

Details

Kind
Godot component
Engine
Godot 4.3 or later
Files
11 files, 85.4 KB
Licence
MIT
Declared effects
reads files, runs commands
Checked with
Godot 4.7.2, headless
Checks
godot parse check only, godot gdscript tests, godot tests reject gutted component, godot editor import, godot contract reflection, godot readme usage compiles
Techniques
axial and cube hex coordinates, cube rounding, linear interpolation line drawing, breadth-first search, A* search with a binary heap
Tags
hex grid, hexagon, axial coordinates, pathfinding, a star, grid math, strategy
Identity
library.supply.creative_originals.f2023b0c32fb083770912a18.eef0149e69fdb623
Version
eef0149e69fdb623b002a69d1ef12b112ca040dee10836a3fbf1ec1b443dac29

The version is the SHA-256 of the item your harness downloads; every file in it names its own checksum.

Something wrong with this item, its rights or its safety? Report it on the support page, or from your harness after a download.