I need to find the distance of hexagonal grids in numbers mathematically, something like this:
I’ve actually created a script for this job, but it’s very slow, long and tends to break (Literally breaking the whole system, I’m rewriting the entire thing currently)
I did do research, but didn’t really find anything helpful to me
LMK if I missed anything!
Hi! May I ask you, how do you represent these tiles? Are they actual parts in the game? Can you please just give a bit more detail in that regard and I may be able to help you.
Following the example, I will try to find the distance between one of the red colored tiles and the white tile (The one with the number 0) and it should return the number 1
Hi again!
If all you need find the distance from the white tile to any tile I would put an IntValue “Distance” and manually enter the value for every tile and then you can read it.
If you need different functionality let me know, and about my last response I should have been more specific, I was looking to understand what getting the distance would help you with.
local hex1, hex2 = script.Parent["1"], script.Parent["2"];
local dist = ((hex2.CFrame:ToObjectSpace(hex1.CFrame)).Position / hex2.Size);
print(math.round(math.abs(dist.Magnitude))) -- prints distance from hex2 to hex1
print(dist);
EDIT: It might add 1 to longer distances due to 1/2 of each start and end tile being omitted so just -1 if it’s greater than like 3 or something
Thank you! I fixed it to function properly, thanks!
local dist = math.abs((hex2.CFrame:ToObjectSpace(hex1.CFrame). Position / hex2.Size).Magnitude)
dist = math.ceil(dist >= 3 and dist + 1 or dist)
print(dist)