Image explaining the coordinate system
so, sadly i don't know which coordinate system you used back then, cause the link does not work anymore, but most of the solutions posted here did not work for me.
This is the coordinate system i used:
------
------ 0, +1 ------
-1, +1 ------ +1, 0
------ 0, 0 ------
-1, 0 ------ +1, -1
------ 0, -1 ------
------
--------------------------
| -1, +1 | 0, +1 | |
|--------------------------|
| -1, 0 | 0, 0 | +1, 0 |
|--------------------------|
| | 0, -1 | +1, -1 |
--------------------------
And this is the code / formula that worked for me for the points (x1,y1) and (x2,y2):
public int distance(int x1, int y1, int x2, int y2){ //distance of hexfields, 1 is source 2 is target
int dx = Mathf.Abs(x1 - x2);
int dy = Mathf.Abs(y1 - y2);
if(dx == 0){ return dy; }
else if(dy == 0){ return dx; }
else{
if(x2 < x1 && y2 < y1){ //empty Corner
return dx+dy;
}else if(x2 < x1 && y2 > y1){ //Filled Corner
return Mathf.Max(dx, dy);
}else if(x2 > x1 && y2 < y1){ //Filled Corner
return Mathf.Max(dx, dy);
}else if(x2 > x1 && y2 > y1){ //empty Corner
return dx+dy;
}else return 0;
}
}
This could of course be optimized in terms of code quality but might be easier to understand as it is right now