I have a hexagonal grid with variable radius. My entity can move exactly two hexes per turn.
How should I calculate next step towards border and afterwards travelling clockwise around map?
Preferred movement at the boundary
Character should stay at the border while moving counter-clockwise every turn.
Example movement at the middle
Character should move 1 or 2 hexes towards edge every turn.
I can't figure out simple math to do this.
Edit:
This is how I did movement at the boundary:
var x = pos.x;
var y = pos.y;
var z = -pos.x-pos.y;
var dx = 0;
var dy = 0;
if (x == -radius && z > 1) { dy = 2; }
else if (x == -radius && z == 1) { dx = 1; dy = 1; }
else if (y == radius && x < -1) { dx = 2 }
else if (y == radius && x == -1) { dx = 2; dy = -1; }
else if (z == -radius && y > 1) { dx = 2; dy = -2; }
else if (z == -radius && y == 1) { dx = 1; dy = -2; }
else if (x == radius && z < -1) { dy = -2; }
else if (x == radius && z == -1) { dx = -1; dy = -1; }
else if (y == -radius && x > 1) { dx = -2; }
else if (y == -radius && x == 1) { dx = -2; dy = 1; }
else if (z == radius && y < -1) { dx = -2; dy = 2; }
else if (z == radius && y == -1) { dx = -1; dy = 2; }
Any ideas how should I clean this up?
Shortest path to boundary is probably easiest to calculate from x, y and z.