Open m21-cerutti opened 1 month ago
Just for visibility, need to verify it would not impact 3D version (like grid visualisation etc) https://github.com/godotengine/godot/pull/85890
This is something to document as a first step, we can't change the tile shape directly
Adding a regular hexagon tile would be something for a proposal IMO
But are you sure you can't achieve this by just adjusting your tile size?
Would be great for documentation as first step indeed.
But handling irregular hexagon not means that distance calculation would be biaised ? Since we use tile_size for positions when creating after that AStar or whatever grid pathfinding algorithm we use. I wrote it as bug since I am really not sure this choice was intended, but need some verifications I can't afford.
Also it's a pain to fix it exactly to the size of the regular one, since we make those tiles with a tile_size in mind (like 64x64 or other size), tweaking it with a 13.6 pixel separation not scale.
Hello, After some time I was messing with pathfinding, and with no surprise it have an impact. When using global position with
func astar_add_walkable_cells():
var points_array = []
for point in get_used_cells(0):
var position_cell = to_global(map_to_local(point))
...
astar_node.add_point(point_index, position_cell, tile_data.get_custom_data("Cost"))
return points_array
And debug it back... (pink global distance, red cost)
We can see cells are not equally distanced. And offset coordinates seems correct
In this video 115 1 + 115 10 < 128 * 10 so it doesn't takes the shortest path. https://github.com/godotengine/godot/assets/23432929/7a8d7a45-a2e3-45da-8f93-82c9e8f6399a
I was preparing a public template for hexagon map so feel free to test it on my code https://gitlab.com/neitherlands/godot-4-hexagon-template-2d
Tested versions
System information
Godot v4.2.2.stable - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 Ti (NVIDIA; 32.0.15.5585) - 11th Gen Intel(R) Core(TM) i7-11700KF @ 3.60GHz (16 Threads)
Issue description
Seems all the grid with hexagon are not regular ones mathematically, since the outline touch the border on two faces. To illustrate, the difference beetween this one (regular)
and this one (not regular)
is subtle, but that means distance on extremity are not the same on the second case (and could lead to wrong AStar ?)
Inside Godot TileSet, we use not regular one :
Steps to reproduce
Minimal reproduction project (MRP)
Chara_TopDown_Hexagon.zip