0

I have a hexagonal grid with variable radius. My entity can move exacly 2 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.

Preferred movement at the boundary

Example movement at the middle

Character should move 1 or 2 hexes towards edge every turn.

enter image description here enter image description here

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 propably easiest to calculate from x, y and z.

warbaque
  • 583
  • 1
  • 8
  • 18
  • Why does 1,-2 move to 0,-3 and not -1,-2? Similarily why does 0,-1 move to -2,0 and not to -2,-1 (two steps out) or -2,1? – Taemyr Mar 13 '16 at 11:51
  • That was just an example. Only rules are that character moves towards boundary if it can. And if it can't go further, then move counter-clockwise. Every turn it must move 2 hexes. – warbaque Mar 13 '16 at 11:59
  • For anyone looking at this question, see [the version on gamedev.stackexchange](http://gamedev.stackexchange.com/questions/118157/what-is-easiest-way-to-move-towards-and-along-the-edge-on-a-hex-grid/118184#118184) instead. – amitp Jul 20 '16 at 17:34

0 Answers0