Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hexagon Tileset 2D don't use regular hexagon #92338

Open
m21-cerutti opened this issue May 24, 2024 · 5 comments
Open

Hexagon Tileset 2D don't use regular hexagon #92338

m21-cerutti opened this issue May 24, 2024 · 5 comments

Comments

@m21-cerutti
Copy link

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)

Regular_1

and this one (not regular)

NotRegular_1

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 :

image

image

Steps to reproduce

  1. Import a tileset with regular hexagon
  2. See difference

Minimal reproduction project (MRP)

Chara_TopDown_Hexagon.zip

@m21-cerutti
Copy link
Author

m21-cerutti commented May 24, 2024

Just for visibility, need to verify it would not impact 3D version (like grid visualisation etc)
#85890

@m21-cerutti m21-cerutti changed the title Hexagon Tileset don't use regular hexagon Hexagon Tileset 2D don't use regular hexagon May 24, 2024
@AThousandShips
Copy link
Member

AThousandShips commented May 25, 2024

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?

@m21-cerutti
Copy link
Author

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.

@m21-cerutti
Copy link
Author

m21-cerutti commented Jun 26, 2024

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)
image
We can see cells are not equally distanced. And offset coordinates seems correct
image

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

@m21-cerutti
Copy link
Author

Have made a demo project, could be used to experiment
godotengine/godot-demo-projects#1085

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants