If you want to ignore euclidean distance and use only connections it is trivial:
extends AStar
func _compute_cost(_from_id, _to_id):
return 1.0
func _estimate_cost(_from_id, _to_id):
return 1.0
Those functions are called for points that have a connection between them.
Here's a code that uses above subclass:
extends Node
var astar = preload("res://NoneuclideanAStar.gd").new()
const pointsToWeight := {
Vector3(0,0,0) : 5, Vector3(1,0,0) : 1, Vector3(2,0,0) : 3,
Vector3(0,1,0) : 3, Vector3(1,1,0) : 4, Vector3(2,1,0) : 4,
Vector3(0,2,0) : 3, Vector3(1,2,0) : 3, Vector3(2,2,0) : 4,
}
const connections := [
[00,10], [10,20], [01,11], [11,21], [02,12], [12,22], # horizontally
[00,01], [01,02], [10,11], [11,12], [20,21], [21,22], # vertically
[10,01], [10,21], [01,12], [21,12], #diagonally
]
func _ready():
for point in pointsToWeight.keys():
var id = point.x * 10 + point.y
astar.add_point( id, point, pointsToWeight[point] )
for conn in connections:
astar.connect_points(conn[0], conn[1])
var path = astar.get_point_path(10, 12)
print(path)
It prints
[(1, 0, 0), (0, 1, 0), (1, 2, 0)]