โ† All examples

godot components

Hex grid math on axial coordinates

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.

What this component contains

  • 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

How it works

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/

Recorded checks

godot 4.7.2.stable.official.ed1daf0bf

  • godot_parse_check_only
  • godot_gdscript_tests
  • godot_tests_reject_gutted_component
  • godot_editor_import
  • godot_contract_reflection
  • godot_readme_usage_compiles

Limits to consider

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.